0
votes

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
Jeremy, add a programming language tag, I'd do it for you but I'm bad at guessing ;) This will increase visibilty for your question and the number of answers! - Andreas Dolk
You mean like C#? i hadnt' realized that was neccessary - Jeremy Holt

1 Answers

1
votes

I think there is built in support for this using:

Scan(assemblyScanner =>
             {
                 assemblyScanner.TheCallingAssembly();
                 assemblyScanner.AddAllTypesOf(typeof (IRepository<>));
                 assemblyScanner.ConnectImplementationsToTypesClosing(
                    typeof(IRepository<>));
             });