如何跨多个程序集使用WindsorInstaller进行注册 [英] How do i use WindsorInstaller across multiple assemblies for registration
问题描述
我正在使用温莎城堡(Castle Windsor)来处理我的依赖项注入,并且到目前为止,它一直都很好用。
I am using Castle Windsor to handle my Dependency Injection and it has been working great up until now.
但是,我现在正在尝试扩展我的项目并添加一些其他库-我现在正在努力寻找利用Castle的最佳方法。
However, i am now trying to extend my project and add some additional libraries - im now struggling to figure the best way to leverage Castle.
我目前有以下程序集
MyProject.Interfaces(包含IDBContext接口)
MyProject.BusinessLogic(包含Castle Windsor实现) )
MyProject.DataAccess(包含IDBContext的实现)
MyProject.Interfaces (contains IDBContext interface) MyProject.BusinessLogic (contains the Castle Windsor implementation) MyProject.DataAccess (contains implementation of IDBContext)
我目前有一个名为DBContextInstaller的安装程序,它仅实现以下内容:
I currently have an installer called DBContextInstaller and it simply implements the following:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly()
.BasedOn<IDBContext>()
.WithService
.DefaultInterface()
.Configure(reg => reg.LifeStyle.PerWebRequest));
}
我现在在这个项目中有了一个新的Assembly-称之为MyProject.UserService
I now have a new Assembly in this project - lets call it MyProject.UserService and it happens to have a new concrete implementation of IDBContext.
所以我的问题是-如何更改Container.Register语句以检查多个库。注意:我完全希望将来有越来越多的库添加到此方案中。我希望这个安装程序能找到所有实现。
So my question - how can i change my Container.Register statement to have it inspect multiple libraries. NOTE i totally expect to have more and more libraries added to this scenario in the future. I would love for this installer to just find all implementations.
TIA
推荐答案
您可以使用AllTypes.FromAssemblyInDirectory ...
You could use AllTypes.FromAssemblyInDirectory...
container.Register(AllTypes.FromAssemblyInDirectory(new AssemblyFilter(folderPath)));
这篇关于如何跨多个程序集使用WindsorInstaller进行注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!