开发者

Castle-Windsor: Overwrite a component in the future

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 app开发者_如何学Golication 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.


George,

I believe what you're looking for is IHandlerSelector.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜