Replace the implementation for a given factory (the "original"), such
that future calls to $(original) will call or construct the replacement
instead.
Replacements are run under the same conditions as any other
SingletonFactory: root job, no reactive reads, and generator
function auto-fork()ing. They don't have to be implemented the
same way, though: the original could be a class, and the replacement a
function, or vice versa: they just need to produce something that
satisfies the type expected by the original's consumers.
The replacement can even be a generic wrapper, as the current creation
target (i.e. the "original" factory) can be obtained via
$cache.creating(). If the replacement is omitted, null, or
undefined, future calls will invoke the original factory again.
(Note: in all cases the replacement will not take effect if there's
already a cached singleton, so you may wish to also call
$cache.unset() to ensure a future call is actually executed.)
Replace the implementation for a given factory (the "original"), such that future calls to
$(original)will call or construct the replacement instead.Replacements are run under the same conditions as any other SingletonFactory: root job, no reactive reads, and generator function auto-fork()ing. They don't have to be implemented the same way, though: the original could be a class, and the replacement a function, or vice versa: they just need to produce something that satisfies the type expected by the original's consumers.
The replacement can even be a generic wrapper, as the current creation target (i.e. the "original" factory) can be obtained via $cache.creating(). If the replacement is omitted, null, or undefined, future calls will invoke the original factory again.
(Note: in all cases the replacement will not take effect if there's already a cached singleton, so you may wish to also call $cache.unset() to ensure a future call is actually executed.)