Castle Windsor - One class implementing multiple interfaces

我与影子孤独终老i 提交于 2020-01-05 05:29:20

问题


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:-

Can't create component 'MyApp.Admin.Presenters.SnippetPresenter' as it has dependencies to be satisfied. MyApp.Admin.Presenters.SnippetPresenter is waiting for the following dependencies: Services: - MyApp.Admin.Controllers.ISnippetController which was not registered.

If I switch the order of the registrations around it complains that it cannot find the 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? (p.s. im using .net 3.5, windsor RC3)


回答1:


Have you tried registering with different syntax (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




回答2:


Updated to the latest trunk (1015) and used forwarded types which fixed the issue. :-)



来源:https://stackoverflow.com/questions/435629/castle-windsor-one-class-implementing-multiple-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!