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> ...
有了这样的结构,我希望将实现该服务的ConcreteService
类注册到IService<SomeType>
中。在Castle Windsor中,我该如何做呢?一一实现的方式如下:
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<>
进行全部注册呢?