我尝试注册基于泛型类的具体类,而这个泛型类是基于泛型接口的。问题是如何在 Castle Windsor 和 ASP.NET Boilerplate 中执行此操作,这样我就不需要很多代码来一一注册它。
public interface IService<T> where T: class ...
public class Service<T, TE, TPrimary> : IService<T> where T: class ...
public class ConcreteService : Service<SomeType, SomeType2, string> ...
public class AnotherConcreteService : Service<AnotherSomeType, AnotherSomeType2, string> ...
有了这样的结构,我想注册到实现这个服务的IService<SomeType>类ConcreteService。我怎么能用温莎城堡做到这一点?一个一个的实现看起来像这样:
IocManager.IocContainer.Register(Component.For(typeof(IQueryService<SomeType>))
.ImplementedBy(typeof(ConcreteService)).Named("ConcreteTest"));
IocManager.IocContainer.Register(Component.For(typeof(IQueryService<AnotherSomeType>))
.ImplementedBy(typeof(AnotherConcreteService)).Named("AnotherConcreteTest"));
我想要的用法:
var test1 = IocContainer.Resolve<IQueryService<SomeType>(); // Here should be ConcreteService
var test2 = IocContainer.Resolve<IQueryService<AnotherSomeType>(); // Here should be AnotherConcreteService
通过逐行方法,它可以工作,但是如何注册所有基于IQueryService<>?
扬帆大鱼
饮歌长啸
相关分类