Component decorators

Reference | Component Container


If your component implements ioc.ComponentDecorator it will be considered a decorator and will be integrated into the container startup process.

After the container has instantiated and configured all registered components, but before any StartComponent() methods are called, all decorators will be given access to all other registered components.

This technique is useful in handful of situations:

The interface requires you to implement two methods:

OfInterest

Your decorator will have every registered component passed (one at a time) to its OfInterest method. The component is represented by an ioc.Component struct which provides access to the component’s name and the instance of the struct the component represents.

Your decorator can decide whether the supplied component is something the decorator wants to either modify or gain access to, usually by checking the component’s type.

DecorateComponent

If your OfInterest method returns true, the DecorateComponent() method is called. This is where your decorator can modify the supplied component or capture a reference to it.


Next: Configuration

Prev: Component lifecycle