diContainer

creates and returns an empty IOC-Container. The first item will be created and stored only after it is requested.

Import

import diContainer from 'true-di';
const { default: diContainer } = require('true-di');

Declaration

function diContainer<IContainer extends object>(factories: IFactories<IContainer>): IContainer
function diContainer<Private extends object, Public extends object>(
  privateFactories: Pick<IFactories<Private & Public>, keyof Private>,
  publicFactories: Pick<IFactories<Private & Public>, keyof Public>,
): Public

Arguments (1st overload)

  • factories: IFactories<IContainer> -- plain JavaScript object that is used as a map, where field names are item names and values are factory-functions that create correspondent items. To support property/setter injections the values of the factories-object could be a tuple (array), the first item of such tuple is a factory function and the second is an instance initializer.

Returns (1st overload)

  • container: IContainer

Arguments (2nd overload)

  • privateFactories: Pick<IFactories<Private & Public>, keyof Private> - the factories of the private services

  • publicFactories: Pick<IFactories<Private & Public>, keyof Public> - the factories of the public services

Returns (2st overload)

  • container: Public - container resolving public services only

Factory Types

Type IFactories<IContainer>

Type declaration:

Type IFactory<IContainer, name>

Type declaration:

Type IFactoryTuple<IContainer, name>

Type declaration:

Type IInstanceInitializer<IContainer, name>

Type declaraion:

The container doesn't have any methods but only properties copied from the factories. You can get all property descriptors using standard JS-API.

Example "Getting Started"

Example "Exposing only ECommerceService"

Example "Working With Cyclic Dependencies"

Last updated

Was this helpful?