简体   繁体   English

使用通用开放类型参数连接StructureMap

[英]Wire up StructureMap with generic open type arguments

How would I wire up StructureMap with the following: 我如何使用以下方法连接StructureMap:

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. 我有Repository的许多具体实现,需要StructureMap自动将它们连接起来。

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). 但是我只得到StructureMap异常代码:25(无解释)。

Is this at all possible? 这是可能吗?

Many thanks Jeremy 非常感谢杰里米

I think there is built in support for this using: 我认为使用以下命令内置支持:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM