I want to redefine an (default) implementation in a given windsor-container. Is that what OverWrite is for? Doesn't work, though.
container.Register(
Component.For<IServiceOperationAuthorization>()
.OverWrite()
.Instance(_authorization)
);
Any other Ideas?
cheers, Lars
You could very simply do this in the place you need to override the default implementation. This is an example from our integration tests. Both implementations are now registered but your code will use the default one, which is the one you've just registered. Works like a bomb and doesn't have any impact on the rest of the application:
var sendMailStub = MockRepository.GenerateStub<ISendMail>();
_container.Register(
Component
.For<ISendMail>()
.Instance(sendMailStub)
.IsDefault()
);
I agree with Krzysztof that this is usually not a good idea... However as far as I can tell OverWrite() does not overwrite the default component, it just overwrites the lifestyle defined by attribute (i.e. [Singleton]).
If you want to replace a component, you can use container.Kernel.RemoveComponent(string key)
followed by the registration of the new component.
Here's an example where this does make sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With