Posts

Showing posts from June, 2011

Implementing Decorator pattern with Windsor Container

The Decorator design pattern makes it possible to extend an abstraction's behavior without touching the implementing class at all. I didn't use to use it as often as I should in the past, but as I'm reading (for the second time, btw) the fresh edition of the excellent  Dependency Injection in .NET  book by  Mark Seemann , I'm getting to really understand how useful it could be. But the most amazing thing is that how elegantly Windsor Container  wires up Decorators. Everything you have to do is register the Decorators in outside-in order and resolve the abstraction. For example, if we have Abstraction interface and two implementations - Impl1 and Impl2: and we would like Impl1 be injected into Impl2 via its constructor, then all we have to do is register Impl2 as the implementation of Abstraction, then register Impl1 in the same way (no explicit names are required for both). As a result, when we resolve Abstraction from the container, we get instance of Impl2 with it