Base class for Context-based decoration, specifically where both the instance being decorated (InstanceT ) and the data being used as a decoration (DecorationT ) are class types.
Automatically removes decorations when the decorated instance is cleaned up.
As described in the remarks for DecoratorBase<InstanceT, DecorationT>, the simplest way to associate an instance with a decoration is to create a map or Dictionary from InstanceT to DecorationT , then store the association there. One often-unintended effect of this is that, because C# is a managed language, both the instance and the decoration will be "pinned into existence": because the (long-lived) decorator dictionary contains references to the instance, the garbage collector will never be able to clean it up, even if nothing else refers to it, which means the fact of being decorated can change the lifespan of the instance.
ClassToClassDecorator avoids this problem by capturing only a weak reference to the instance (the decoration is still strongly referenced and thus "pinned into existence"). Consequently, decorating instances using a
ClassToClassDecorator is a non-invasive operation which will not alter the lifespan or other behavior of the decorated instance.