Base class for Context-based decoration, specifically where the instance being decorated (InstanceT ) is not a class type, but the data being used as a decoration (DecorationT ) is.
Automatically removes decoration relationships when the decoration is cleaned up.
As with ClassToClassDecorator<InstanceT, DecorationT> and other descendants of DecoratorBase<InstanceT, DecorationT>, a goal of
ValueToClassDecorator is to be non-invasive and avoid altering behavior based on decoration. However, because InstanceT is not a class type, its lifecycle cannot be used to determine when to automatically remove its entry in the decorator; thus, even if the value decorated is no longer in use, decoration based on the instance lifecycle would continue to "pin the
decoration into existence" indefinitely. To avoid this,
ValueToClassDecorator automatically cleans up its decoration relationships based on the lifecycle of the
decoration, meaning once no references to the decoration remain outside the decorator, the relationship will be cleaned up to avoid leaks.
There are scenarios where this behavior is undesirable where it is better for the decorator to own a reference to the decoration such that it can "pin it into existence" despite the fact that
InstanceT has no lifecycle. In such scenarios, a simple dictionary singleton on the
Context is a better choice than any descendent of DecoratorBase<InstanceT, DecorationT> as only manual lifecycle management is appropriate.