New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using dynamic dependencies with components for the same service #112
Comments
Reverse the order of your registrations, that is, register component1 then component2. For example, see https://nexussharp.wordpress.com/2012/04/22/castle-windsor-how-to-register-components/ Also see http://mikehadlow.blogspot.com.au/2010/01/10-advanced-windsor-tricks-4-how-to.html, although it suggests the ordering you had... Hmm 😕 I don't have my "dependency injection in .NET" book handy :) |
@IanYates see https://github.com/castleproject/Windsor/blob/master/docs/registering-components-one-by-one.md#register-more-components-for-the-same-service
It works perfectly for not dynamic parameters. For example: Component
.For<ITestRegistration>()
.ImplementedBy<TestRegistration>()
.DependsOn(Dependency.OnValue("uri", new Uri("http://test.com"))
.Named("component1") |
True. But that page doesn't discuss decorators - at least not directly. When you try to resolve So registering
Alternatively you can keep your registration order but instruct Windsor that
Now that still doesn't work (and This changes the error message slightly and made the issue more obvious to me It was previously
And with the ServiceOverride it's now
Note that in the first case Windsor is trying to use Your point about the specification of the This is all pointing to a bug IMHO with the I haven't given you a fix or even a good explanation but I hope there's something there of use :) If one of the core Castle devs doesn't pick this up I might step through the code over the Christmas break to see if I can spot what's going wrong and make my first PR to Windsor. |
By the way, my code snippet works if I add TypedFactoryFacility registration. |
If "component2" depends on a named component, the dynamic DependsOn are ignored and the creation fails. This means that you cannot register a decorator that decorates different instances of the same service. For instance if you have class BogusClass that implements BogusInterface, and you have multiple instances of BogusClass with different constructor properties specified in a dynamic DependsOn, you cannot have a decorator.
For completeness:
One workaround is to use
|
this code thrown on resolve component 2 with message:
An unhandled exception of type 'Castle.MicroKernel.Handlers.HandlerException' occurred in Castle.Windsor.dll
Additional information: Can't create component 'component2' as it has dependencies to be satisfied.
'component2' is waiting for the following dependencies:
A dependency cannot be satisfied by the component itself, did you forget to make this a service override and point explicitly to a different component exposing this service?
The following components also expose the service, but none of them can be resolved:
'component1' is waiting for the following dependencies:
The text was updated successfully, but these errors were encountered: