IHandlerSelector がトリックを行うように見えます:
public class DecoratorHandler : IHandlerSelector
{
private readonly IWindsorContainer _container;
private readonly HashSet<Type> _decoratedTypes = new HashSet<Type>();
public DecoratorHandler(IWindsorContainer container)
{
_container = container;
}
public bool HasOpinionAbout(string key, Type service)
{
return _decoratedTypes.Contains(service);
}
public IHandler SelectHandler(string key, Type service, IHandler[] handlers)
{
return handlers[handlers.Length - 1];
}
public void Register<TTarget, TDecorator>() where TDecorator : TTarget, IDecorator<TTarget>
{
_container.Register(Component.For<TTarget>().ImplementedBy<TDecorator>());
_decoratedTypes.Add(typeof(TTarget));
}
}
と
_decoratorHandler = new DecoratorHandler(_container);
_container.Kernel.AddHandlerSelector(_decoratorHandler);