Type alias ContainerFreeStrategy

ContainerFreeStrategy: "throw" | "null" | "returnNew"

A description of how TypeDI should react when a container with the specified ID does not already exist in the registry.

There are three possible values:

  • throw: Throw an error.
  • null: Return null.
  • returnNew: Return a newly-created container instance. This is the default.

Example

Here is an example:

// When the container doesn't already exist...
assert(defaultContainer.ofChild(Symbol('my-unique-id'), { onFree: 'null' }) === null);

// We can also 'returnNew' to use the default behaviour.
defaultContainer.ofChild(Symbol(), { onFree: 'returnNew' });

// Or, we can throw if the container *should* already exist.
defaultContainer.ofChild(Symbol(), { onFree: 'throw' }); // Throws an error.

Generated using TypeDoc