0

How would I wire up StructureMap with the following:

public Interface IRepository<T, TIdentity>{}
public abstract class Repository<T, TIdentity> : IRepository<T, TIdentity>, other interfaces

I have many concrete implementations of Repository and need StructureMap to wire them up automatically.

public class JournalRepository : Repository<Journal,int>{}
public class UsersRepository : Repository<Users,int>{}
public class AccountGroupsRepository : Repository<Accounts,string>{}

etc.

I've tried:

 x.ForRequestedType(typeof(IRepository<,>))
.TheDefaultIsConcreteType(typeof(Repository<,>));

but I just get StructureMap Exception Code: 25 (with no explanation).

Is this at all possible?

Many thanks Jeremy

Jeremy Holt
  • 325
  • 6
  • 16

1 Answers1

1

I think there is built in support for this using:

Scan(assemblyScanner =>
             {
                 assemblyScanner.TheCallingAssembly();
                 assemblyScanner.AddAllTypesOf(typeof (IRepository<>));
                 assemblyScanner.ConnectImplementationsToTypesClosing(
                    typeof(IRepository<>));
             });
PHeiberg
  • 29,411
  • 6
  • 59
  • 81
  • Excellent - thanks very much - I just wish I could find the documentation for StructureMap – Jeremy Holt Aug 31 '10 at 22:36
  • The docs are available at http://structuremap.github.com/structuremap/index.html otherwise the google group is usually most helpful http://groups.google.com/group/structuremap-users?hl=en – PHeiberg Sep 01 '10 at 07:58