The short version is you can use the 'DependsOn' and 'Dependency.OnComponent<T, U>' methods when registering your components to do this pretty easily. You can use an installer that looks something like this:
public class ChainOfResponsibilityInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IChainItem>()
.ImplementedBy<ChainItemOne>()
.DependsOn(Dependency.OnComponent<IChainItem,ChainItemTwo>()),
Component.For<IChainItem>()
.ImplementedBy<ChainItemTwo>()
.DependsOn(Dependency.OnComponent<IChainItem, ChainItemThree>()),
Component.For<IChainItem>()
.ImplementedBy<ChainItemThree>());
}
}
I've put a very basic project up on GitHub - https://github.com/StephenFriend/ChainOfResponsibility-with-Castle - to demonstrate an actual working solution.
No comments:
Post a Comment