问题描述
我使用我的。我也有类似以下内容的结构的应用程序:
I use Castle Windsor as my IoC container. I have an application that has a structure similar to the following:
- MyApp.Services.dll
-
IEmployeeService
-
IContractHoursService
-
...
- MyApp.Services.dll
IEmployeeService
IContractHoursService
...
-
的EmployeeService:MyApp.Services.IEmployeeService
-
ContractHoursService :MyApp.Services.IContractHoursService
-
...
EmployeeService : MyApp.Services.IEmployeeService
ContractHoursService : MyApp.Services.IContractHoursService
...
我使用的,而且,我有一个新的组件添加到XML配置文件。我想改用这一切都转移到但还没有制定出的究竟的正途做我想做呢。
I use the XML configuration at the moment, and every time I add a new IService/Service pair, I have to add a new component to the XML configuration file. I want to switch all this over to the fluent registration API but haven't worked out exactly the right recipe to do what I want yet.
谁能帮助?生活方式都将是
单
。Can anyone help? The lifestyles will all be
singleton
.在预先感谢。
推荐答案
通过
AllTypes
您可以轻松地做到这一点:With
AllTypes
you can easily do this:通过:在
注册组件一个接一个也可以非常重复性的工作。还记得注册的每个新型添加可迅速导致挫折。幸运的是,你不必这样做,至少始终。通过使用AllTypes入门级可以执行的根据您指定的某些特定类型特征组注册。
我觉得你的注册会是什么样子
I think your registration would look like:
AllTypes.FromAssembly(typeof(EmployeeService).Assembly) .BasedOn<IEmployeeService>() .LifeStyle.Singleton
如果您实现一个基本类型,如
IService
在你的界面,您可以同时使用下面的结构他们都注册:If you implement a base type, like
IService
on your interfaces, you can register them all at once using the following construct:AllTypes.FromAssembly(typeof(EmployeeService).Assembly) .BasedOn<IService>() .WithService.FromInterface() .LifeStyle.Singleton
有关更多示例,请参阅文章。这对可能性是什么一个很好的说明。
For more examples, see the article. This has a very good description on what the possibilities are.
这篇关于温莎城堡:从一个装配自动注册类型从另一个实现接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-