【发布时间】:2012-11-26 13:18:21
【问题描述】:
我的解决方案的核心项目中有一个接口:IPersonManager,它有两个具体的实现,属于各自的项目。
在我的 web 项目中,有一个 MVC 区域代表这两个项目,每个区域都有一个框架安装程序类,它将人员管理器类注册到每个区域的接口,如下所示:
container.Register(AllTypes
.FromAssemblyNamed("MySolution.MyProject")
.Where(t => t.Name.EndsWith("Manager"))
.WithService.DefaultInterface()
.Configure(x => x.LifeStyle.PerWebRequest)
);
注册后,当我在内核上为 IPersonManager 接口获取处理程序时,我得到以下信息:
{Castle.MicroKernel.IHandler[2]}
[0]: Model: {MySolution.Core.Interfaces.Services.IPersonManager}
/ {MySolution.Area1.PersonManager}
[1]: Model: {MySolution.Core.Interfaces.Services.IPersonManager}
/ {MySolution.Area2.PersonManager}
所以我可以看到两个实现都已注册。
问题是当我在网站上的Area2时,windsor正在解析Area1的接口实现而不是Area2。
好像温莎只是把最先注册的那个还给我。有没有办法恢复基于 MVC 区域的正确实现?
【问题讨论】:
标签: model-view-controller inversion-of-control castle-windsor ioc-container