我的想法是,我有一个带有很多接口的Core项目,还有一个带有实现(一切都是1-to-1)的Data and Service项目,例如:

Core { IFooRepo, IBarRepo, IFooService, IBarService}
Data {FooRepo: IFooRepo, BarRepo : IBarRepo}
Service {FooService : IFooService, BarService : IBarService}


所以我想要

register(Core, Data);
register(Core, Service);


有很多IoC容器,我不知道其中哪个容器可以做到这一点,或者更接近此解决方案,有人知道吗?

最佳答案

通过Windsor,您可以轻松地将类注册为它们公开的接口(全部或选择性地)。 (see the documentation)。

它没有针对您的场景的OOTB支持(过滤实现的接口以仅包括来自特定程序集的接口),但是(对于Windsor中的所有内容)可以使用钩子轻松实现。

container.Register(
   AllTypes.FromAssemblyContaining<SomeClass>()
      WithService.Select((type, @base) =>
         type.GetAllInterfaces()
             .Where(i => i.Assembly == yourInterfacesAssembly)))
);

关于caSTLe-windsor - IoC容器,无需配置(组装到组装)即可自动注册所有内容(非通用),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4474776/

10-13 01:14