问题
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