views:

55

answers:

1

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

+1  A: 

I think there is built in support for this using:

Scan(assemblyScanner =>
             {
                 assemblyScanner.TheCallingAssembly();
                 assemblyScanner.AddAllTypesOf(typeof (IRepository<>));
                 assemblyScanner.ConnectImplementationsToTypesClosing(
                    typeof(IRepository<>));
             });
PHeiberg
Aha. This worked for me. http://bit.ly/6MvOAw
Arnis L.
Excellent - thanks very much - I just wish I could find the documentation for StructureMap
Jeremy Holt
The docs are available at http://structuremap.github.com/structuremap/index.htmlotherwise the google group is usually most helpful http://groups.google.com/group/structuremap-users?hl=en
PHeiberg