I have the following use case:
I want to register all components shared between all configurations of an application. Then I would like to register a series of dynamically configured "Plugins" which are expressed as custom implementations of IRegistration.
Only then do I resolve my application start point.
One of the things that I would like a plugin to do is overwrite a service implementation. Something like this:
public class SomePlugin {
public void Register(IKernel kernel) {
kernel.RemoveComponent(typeof(DefaultServiceImplementation).FullName);
kernel.Register(
Component.For<IService>()
.ImplementedBy<AlternateServiceImplementation>())
}
}
However this does not work if any of the components already registered have a dependency on IService.
I know that I can register the plugins first, but that's limiting for several other reasons. How can I fulfill my specific requirement?
Best thing I could come up with is something like
kernel.ResolvingComponent += (model, a, b) => {
if(model.Service == typeof(IService))
model.Implementation = typeof(AlternateServiceImplementation);
}
I think this could work in some limited scenarios but it is far from ideal.