简体   繁体   English

温莎城堡-一类实现多个接口

[英]Castle Windsor - One class implementing multiple interfaces

I register my two interfaces on application start as so:- 我在应用程序启动时注册了两个接口,如下所示:

container.Register(Component.For(typeof(IEntityIndexController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient);
container.Register(Component.For(typeof(ISnippetController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient);

Then when I try to run an IoC.Resolve on an object that uses the second interface here (ISnippetController) it throws the following exception:- 然后,当我尝试在此处使用第二个接口的对象(ISnippetController)上运行IoC.Resolve时,将引发以下异常:

Can't create component 'MyApp.Admin.Presenters.SnippetPresenter' as it has dependencies to be satisfied. 无法创建组件'MyApp.Admin.Presenters.SnippetPresenter',因为它具有需要满足的依赖关系。 MyApp.Admin.Presenters.SnippetPresenter is waiting for the following dependencies: Services: - MyApp.Admin.Controllers.ISnippetController which was not registered. MyApp.Admin.Presenters.SnippetPresenter正在等待以下依赖项:服务:-未注册的MyApp.Admin.Controllers.ISnippetController。

If I switch the order of the registrations around it complains that it cannot find the IEntityIndexController. 如果我切换周围的注册顺序,则会抱怨找不到IEntityIndexController。 So it appears it only picks up the first registration of a class, then any further interfaces that map to that same concrete class are ignored. 因此看来,它只选择了类的第一个注册,然后映射到该具体类的所有其他接口都将被忽略。

Is there something obvious here that I'm missing? 有什么明显的我想念的东西吗? (ps im using .net 3.5, windsor RC3) (使用.net 3.5的ps im,温莎RC3)

Have you tried registering with different syntax ( AddComponent<> )? 您是否尝试过使用其他语法( AddComponent<> )注册?

Try updating to latest trunk version and see if it helps. 尝试更新到最新的中继版本,看看是否有帮助。 Looks like a bug to me. 对我来说似乎是个虫子。 If it does not happen, create a test that exhibits the bug, and submit it here 如果没有发生,请创建一个包含该错误的测试,然后在此处提交

Updated to the latest trunk (1015) and used forwarded types which fixed the issue. 更新到最新的中继(1015),并使用转发的类型修复了该问题。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM