Review the following:
ContainerInstance.of('my-container', defaultContainer, {
onConflict: 'throw'
});
Be aware that when returnExisting
is used, you may encounter
unexpected errors if containers with completely different configurations
have the same ID. Therefore, it is discouraged in most situations.
However, for historical reasons, it remains the default.
Consider the following example:
ContainerInstance.of('my-container', null); // Create an orphaned container.
defaultContainer.ofChild('my-container'); // Create a child container.
In the case of returnExisting
, the call to ContainerInstance.ofChild
would return a reference to the orphaned container, which will cause unexpected
runtime errors when your code is unable to resolve symbols from the parent container.
As such, when returnExisting
is utilised, it is heavily recommended to use
unique symbol IDs that are unique to a certain part of your application.
Generated using TypeDoc
A description of how TypeDI should react when a container with the specified ID already exists in the registry.
There are three possible values:
throw
: Throw an error upon conflict.null
: Return null.returnExisting
: Return the existing container.If you pass a ContainerConflictDefinition without this, it will default to
throw
. Otherwise,returnExisting
is the default.