Container
The InversifyJS container is where dependencies are first configured through binding and, possibly later, reconfigured and removed. The container can be worked on directly in this regard or container modules can be utilized.
You can query the configuration and resolve configured dependencies with the get
methods.
You can react to resolutions with container activation handlers and unbinding with container deactivation handlers.
You can create container hierarchies where container ascendants can supply the dependencies for descendants.
For testing, state can be saved as a snapshot on a stack and later restored.
For advanced control, you can apply middleware to intercept the resolution request and the resolved dependency.
You can even provide your own annotation solution.
Container Options
Container options can be passed to the Container constructor, and defaults will be provided if you do not or if you do but omit an option. Options can be changed after construction and will be shared by child containers created from the Container if you do not provide options for them.
defaultScope
The default scope is transient
when binding to/toSelf/toDynamicValue/toService.
Other bindings can only be bound in singleton
scope.
You can use container options to change the default scope for the bindings that default to transient
at the application level:
const container: Container = new Container({ defaultScope: 'Singleton' });
// You can configure the scope when declaring bindings:
container.bind<Warrior>(warriorServiceId).to(Ninja).inTransientScope();
autoBindInjectable
You can use this to activate automatic binding for @injectable()
decorated classes.
Whenever an instance is requested via get
, the container attempts to add a binding if no binding is found for the requested service.
const container: Container = new Container({ autoBindInjectable: true });
// returns false
container.isBound(Ninja);
// returns a Ninja
container.get(Ninja);
// returns true
container.isBound(Ninja);
Manually defined bindings will take precedence:
const container: Container = new Container({ autoBindInjectable: true });
// returns a Ninja
container.bind(Ninja).to(NinjaMaster);
// returns NinjaMaster
container.get(Ninja);
skipBaseClassChecks
You can use this to skip checking base classes for the @injectable
property, which is especially useful if any of your @injectable
classes extend classes that you don't control (third-party classes). By default, this value is false
.
const container = new Container({ skipBaseClassChecks: true });
Container.merge
Container.merge(a: interfaces.Container, b: interfaces.Container, ...containers: interfaces.Container[]): interfaces.Container;
Creates a new Container containing the bindings ( cloned bindings ) of two or more containers:
@injectable()
class Ninja {
public readonly name: string = 'Ninja';
}
@injectable()
class Shuriken {
public readonly name: string = 'Shuriken';
}
const NINJA_EXPANSION_TYPES = {
Ninja: 'Ninja',
Shuriken: 'Shuriken',
} satisfies Record<string, string>;
const ninjaExpansionContainer: Container = new Container();
ninjaExpansionContainer.bind<Ninja>(NINJA_EXPANSION_TYPES.Ninja).to(Ninja);
ninjaExpansionContainer
.bind<Shuriken>(NINJA_EXPANSION_TYPES.Shuriken)
.to(Shuriken);
@injectable()
class Samurai {
public readonly name: string = 'Samurai';
}
@injectable()
class Katana {
public name = 'Katana';
}
const SAMURAI_EXPANSION_TYPES = {
Katana: 'Katana',
Samurai: 'Samurai',
} satisfies Record<string, string>;
const samuraiExpansionContainer: Container = new Container();
samuraiExpansionContainer
.bind<Samurai>(SAMURAI_EXPANSION_TYPES.Samurai)
.to(Samurai);
samuraiExpansionContainer
.bind<Katana>(SAMURAI_EXPANSION_TYPES.Katana)
.to(Katana);
const gameContainer: interfaces.Container = Container.merge(
ninjaExpansionContainer,
samuraiExpansionContainer,
);
applyCustomMetadataReader
applyCustomMetadataReader(metadataReader: interfaces.MetadataReader): void;
Sets a custom metadata reader. See middleware.
applyMiddleware
applyMiddleware(...middleware: interfaces.Middleware[]): void;
An advanced feature that can be used for cross cutting concerns. See middleware.
bind
bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>
Sets a new binding.
createChild
createChild(containerOptions?: interfaces.ContainerOptions): Container;
Create a container hierarchy. Parent ContainerOptions
are provided by default.
get
get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T;
Resolves a dependency by its runtime identifier. The runtime identifier must be associated with only one binding and the binding must be synchronously resolved, otherwise an error is thrown.
const container: Container = new Container();
container.bind<Weapon>('Weapon').to(Katana);
const katana: Weapon = container.get<Weapon>('Weapon');
getAsync
getAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): Promise<T>;
Resolves a dependency by its runtime identifier. The runtime identifier must be associated with only one binding, otherwise an error is thrown.
async function buildLevel1(): Promise<Level1> {
return new Level1();
}
const container: Container = new Container();
container
.bind('Level1')
.toDynamicValue(async (): Promise<Level1> => buildLevel1());
const level1: Promise<Level1> = container.getAsync<Level1>('Level1');
getNamed
getNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T;
Resolves a dependency by its runtime identifier that matches the given named constraint. The runtime identifier must be associated with only one binding and the binding must be synchronously resolved, otherwise an error is thrown:
const container: Container = new Container();
container.bind<Weapon>('Weapon').to(Katana).whenTargetNamed('melee');
container.bind<Weapon>('Weapon').to(Shuriken).whenTargetNamed('ranged');
const katana: Weapon = container.getNamed<Weapon>('Weapon', 'melee');
const shuriken: Weapon = container.getNamed<Weapon>('Weapon', 'ranged');
getNamedAsync
getNamedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): Promise<T>;
Resolves a dependency by its runtime identifier that matches the given named constraint. The runtime identifier must be associated with only one binding, otherwise an error is thrown:
const container: Container = new Container();
container
.bind<Weapon>('Weapon')
.toDynamicValue(async () => new Katana())
.whenTargetNamed('melee');
container
.bind<Weapon>('Weapon')
.toDynamicValue(async () => new Shuriken())
.whenTargetNamed('ranged');
const katana: Promise<Weapon> = container.getNamedAsync<Weapon>(
'Weapon',
'melee',
);
const shuriken: Promise<Weapon> = container.getNamedAsync<Weapon>(
'Weapon',
'ranged',
);
getTagged
getTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T;
Resolves a dependency by its runtime identifier that matches the given tagged constraint. The runtime identifier must be associated with only one binding and the binding must be synchronously resolved, otherwise an error is thrown:
const container: Container = new Container();
container
.bind<Weapon>('Weapon')
.to(Katana)
.whenTargetTagged('faction', 'samurai');
container
.bind<Weapon>('Weapon')
.to(Shuriken)
.whenTargetTagged('faction', 'ninja');
const katana: Weapon = container.getTagged<Weapon>(
'Weapon',
'faction',
'samurai',
);
const shuriken: Weapon = container.getTagged<Weapon>(
'Weapon',
'faction',
'ninja',
);
getTaggedAsync
getTaggedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): Promise<T>;
Resolves a dependency by its runtime identifier that matches the given tagged constraint. The runtime identifier must be associated with only one binding, otherwise an error is thrown:
const container: Container = new Container();
container
.bind<Weapon>('Weapon')
.toDynamicValue(async () => new Katana())
.whenTargetTagged('faction', 'samurai');
container
.bind<Weapon>('Weapon')
.toDynamicValue(async () => new Shuriken())
.whenTargetTagged('faction', 'ninja');
const katana: Promise<Weapon> = container.getTaggedAsync<Weapon>(
'Weapon',
'faction',
'samurai',
);
const shuriken: Promise<Weapon> = container.getTaggedAsync<Weapon>(
'Weapon',
'faction',
'ninja',
);
getAll
getAll(serviceIdentifier: interfaces.ServiceIdentifier<T>, options?: interfaces.GetAllOptions): T[];
Get all available bindings for a given identifier. All the bindings must be synchronously resolved, otherwise an error is thrown:
const container: Container = new Container();
container.bind<Weapon>('Weapon').to(Katana);
container.bind<Weapon>('Weapon').to(Shuriken);
const weapons: Weapon[] = container.getAll<Weapon>('Weapon');
Keep in mind container.getAll
doesn't enforce binding contraints by default in the root level, enable the enforceBindingConstraints
flag to force this binding constraint check:
const container: Container = new Container();
container
.bind<Weapon>('Weapon')
.to(Katana)
.when(() => true);
container
.bind<Weapon>('Weapon')
.to(Shuriken)
.when(() => false);
// returns [new Katana(), new Shuriken()]
const allWeapons: Weapon[] = container.getAll<Weapon>('Weapon');
// returns [new Katana()]
const notAllWeapons: Weapon[] = container.getAll<Weapon>('Weapon', {
enforceBindingConstraints: true,
});
getAllAsync
getAllAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, options?: interfaces.GetAllOptions): Promise<T[]>
Get all available bindings for a given identifier:
const container: Container = new Container();
container.bind<Weapon>('Weapon').toDynamicValue(async () => new Katana());
container.bind<Weapon>('Weapon').to(Shuriken);
const weapons: Promise<Weapon[]> = container.getAllAsync<Weapon>('Weapon');
Keep in mind container.getAll
doesn't enforce binding contraints by default in the root level, enable the enforceBindingConstraints
flag to force this binding constraint check:
const container: Container = new Container();
container
.bind<Weapon>('Weapon')
.toDynamicValue(async () => new Katana())
.when(() => true);
container
.bind<Weapon>('Weapon')
.to(Shuriken)
.when(() => false);
// returns [new Katana(), new Shuriken()]
const allWeapons: Promise<Weapon[]> = container.getAllAsync<Weapon>('Weapon');
// returns [new Katana()]
const notAllWeapons: Promise<Weapon[]> = container.getAllAsync<Weapon>(
'Weapon',
{
enforceBindingConstraints: true,
},
);
getAllNamed
getAllNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T[];
Resolves all the dependencies by its runtime identifier that matches the given named constraint. All the binding must be synchronously resolved, otherwise an error is thrown:
const container: Container = new Container();
interface Intl {
hello?: string;
goodbye?: string;
}
container
.bind<Intl>('Intl')
.toConstantValue({ hello: 'bonjour' })
.whenTargetNamed('fr');
container
.bind<Intl>('Intl')
.toConstantValue({ goodbye: 'au revoir' })
.whenTargetNamed('fr');
container
.bind<Intl>('Intl')
.toConstantValue({ hello: 'hola' })
.whenTargetNamed('es');
container
.bind<Intl>('Intl')
.toConstantValue({ goodbye: 'adios' })
.whenTargetNamed('es');
const fr: Intl[] = container.getAllNamed<Intl>('Intl', 'fr');
const es: Intl[] = container.getAllNamed<Intl>('Intl', 'es');
getAllNamedAsync
getAllNamedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): Promise<T[]>;
Resolves all the dependencies by its runtime identifier that matches the given named constraint:
const container: Container = new Container();
interface Intl {
hello?: string;
goodbye?: string;
}
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ hello: 'bonjour' }))
.whenTargetNamed('fr');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ goodbye: 'au revoir' }))
.whenTargetNamed('fr');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ hello: 'hola' }))
.whenTargetNamed('es');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ goodbye: 'adios' }))
.whenTargetNamed('es');
const fr: Promise<Intl[]> = container.getAllNamedAsync<Intl>('Intl', 'fr');
const es: Promise<Intl[]> = container.getAllNamedAsync<Intl>('Intl', 'es');
getAllTagged
getAllTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T[];
Resolves all the dependencies by its runtime identifier that matches the given tagged constraint. All the binding must be synchronously resolved, otherwise an error is thrown:
const container: Container = new Container();
interface Intl {
hello?: string;
goodbye?: string;
}
container
.bind<Intl>('Intl')
.toConstantValue({ hello: 'bonjour' })
.whenTargetTagged('lang', 'fr');
container
.bind<Intl>('Intl')
.toConstantValue({ goodbye: 'au revoir' })
.whenTargetTagged('lang', 'fr');
container
.bind<Intl>('Intl')
.toConstantValue({ hello: 'hola' })
.whenTargetTagged('lang', 'es');
container
.bind<Intl>('Intl')
.toConstantValue({ goodbye: 'adios' })
.whenTargetTagged('lang', 'es');
const fr: Intl[] = container.getAllTagged<Intl>('Intl', 'lang', 'fr');
const es: Intl[] = container.getAllTagged<Intl>('Intl', 'lang', 'es');
getAllTaggedAsync
getAllTaggedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): Promise<T[]>;
Resolves all the dependencies by its runtime identifier that matches the given tagged constraint:
const container: Container = new Container();
interface Intl {
hello?: string;
goodbye?: string;
}
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ hello: 'bonjour' }))
.whenTargetTagged('lang', 'fr');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ goodbye: 'au revoir' }))
.whenTargetTagged('lang', 'fr');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ hello: 'hola' }))
.whenTargetTagged('lang', 'es');
container
.bind<Intl>('Intl')
.toDynamicValue(async () => ({ goodbye: 'adios' }))
.whenTargetTagged('lang', 'es');
const fr: Promise<Intl[]> = container.getAllTaggedAsync<Intl>(
'Intl',
'lang',
'fr',
);
const es: Promise<Intl[]> = container.getAllTaggedAsync<Intl>(
'Intl',
'lang',
'es',
);
isBound
isBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean;
You can use the isBound
method to check if there are registered bindings for a given service identifier.
interface Warrior {
kind: string;
}
const katanaSymbol: symbol = Symbol.for('Katana');
const warriorSymbol: symbol = Symbol.for('Warrior');
@injectable()
class Ninja implements Warrior {
public readonly kind: string = 'ninja';
}
@injectable()
class Katana {}
const container: Container = new Container();
container.bind<Warrior>(Ninja).to(Ninja);
container.bind<Warrior>(warriorSymbol).to(Ninja);
// returns true
const isNinjaBound: boolean = container.isBound(Ninja);
// returns true
const isWarriorSymbolBound: boolean = container.isBound(warriorSymbol);
// returns false
const isKatanaBound: boolean = container.isBound(Katana);
// returns false
const isKatanaSymbolBound: boolean = container.isBound(katanaSymbol);
isCurrentBound
isCurrentBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean;
You can use the isCurrentBound
method to check if there are registered bindings for a given service identifier only in the current container.
interface Warrior {
kind: string;
}
const katanaSymbol: symbol = Symbol.for('Katana');
const warriorSymbol: symbol = Symbol.for('Warrior');
@injectable()
class Ninja implements Warrior {
public readonly kind: string = 'ninja';
}
@injectable()
class Katana {}
const container: Container = new Container();
container.bind<Warrior>(Ninja).to(Ninja);
container.bind<Warrior>(warriorSymbol).to(Ninja);
const containerChild: Container = container.createChild();
containerChild.bind<Katana>(Katana).to(Katana);
containerChild.bind<Katana>(katanaSymbol).to(Katana);
// returns false
const isNinjaBound: boolean = containerChild.isCurrentBound(Ninja);
// returns false
const isWarriorSymbolBound: boolean =
containerChild.isCurrentBound(warriorSymbol);
// returns true
const isKatanaBound: boolean = containerChild.isCurrentBound(Katana);
// returns true
const isKatanaSymbolBound: boolean =
containerChild.isCurrentBound(katanaSymbol);
isBoundNamed
isBoundNamed(serviceIdentifier: interfaces.ServiceIdentifier<unknown>, named: string): boolean;
You can use the isBoundNamed
method to check if there are registered bindings for a given service identifier with a given named constraint.
const divisor: string = 'divisor';
const invalidDivisor: string = 'InvalidDivisor';
const validDivisor: string = 'ValidDivisor';
const container: Container = new Container();
container
.bind<number>(divisor)
.toConstantValue(0)
.whenTargetNamed(invalidDivisor);
// returns true
const isDivisorBoundInInvalidDivisorName: boolean = container.isBoundNamed(
divisor,
invalidDivisor,
);
container
.bind<number>(divisor)
.toConstantValue(1)
.whenTargetNamed(validDivisor);
// returns true
const isDivisorBoundInValidDivisorName: boolean = container.isBoundNamed(
divisor,
validDivisor,
);
isBoundTagged
isBoundTagged(serviceIdentifier: interfaces.ServiceIdentifier<unknown>, key: string, value: unknown): boolean;
You can use the isBoundTagged
method to check if there are registered bindings for a given service identifier with a given tagged constraint.
const divisor: string = 'divisor';
const container: Container = new Container();
container
.bind<number>(divisor)
.toConstantValue(0)
.whenTargetTagged('isValidDivisor', false);
// returns true
const isDivisorBoundInIsValidDivisorFalseTag: boolean = container.isBoundTagged(
divisor,
'isValidDivisor',
false,
);
container
.bind<number>(divisor)
.toConstantValue(1)
.whenTargetTagged('isValidDivisor', true);
// returns true
const isDivisorBoundInIsValidDivisorTrueTag: boolean = container.isBoundTagged(
divisor,
'isValidDivisor',
true,
);
load
load(...modules: interfaces.ContainerModule[]): void;
Calls the registration method of each module. See ContainerModule API docs
loadAsync
loadAsync(...modules: interfaces.AsyncContainerModule[]): Promise<void>;
As per load but for asynchronous registration.
rebind
rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>;
Replaces all the existing bindings for a given serviceIdentifier
.
The function returns an instance of BindingToSyntax
which allows to create the replacement binding.
const serviceId: string = 'serviceId';
const container: Container = new Container();
container.bind<number>(serviceId).toConstantValue(1);
container.bind<number>(serviceId).toConstantValue(2);
// returns [1, 2]
const valuesBeforeRebind: number[] = container.getAll(serviceId);
container.rebind<number>(serviceId).toConstantValue(3);
// returns [3]
const valuesAfterRebind: number[] = container.getAll(serviceId);
rebindAsync
rebindAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): Promise<interfaces.BindingToSyntax<T>>;
This is an asynchronous version of rebind. If you know deactivation is asynchronous then this should be used.
resolve
resolve<T>(constructor: interfaces.Newable<T>): T;
Resolve works the same way container.get
, but an automatic binding will be added to the container if no bindings are found for the type provided.
import { Container, injectable } from 'inversify';
@injectable()
class Katana {
public hit() {
return 'cut!';
}
}
@injectable()
class Ninja implements Ninja {
public katana: Katana;
constructor(katana: Katana) {
this.katana = katana;
}
public fight() {
return this.katana.hit();
}
}
const container: Container = new Container();
container.bind(Katana).toSelf();
// Ninja is provided and a Ninja bindong is added to the container
const ninja: Ninja = container.resolve(Ninja);
Please note that it only allows to skip declaring a binding for the root element in the dependency graph (composition root). All the sub-dependencies (e.g. Katana
in the preceding example) will require a binding to be declared.
onActivation
onActivation<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, onActivation: interfaces.BindingActivation<T>): void;
Adds an activation handler for all services associated to the service identifier.
interface Weapon {
damage: number;
}
export class Katana implements Weapon {
#damage: number = 10;
public get damage(): number {
return this.#damage;
}
public improve(): void {
this.#damage += 2;
}
}
const container: Container = new Container();
container.bind<Weapon>('Weapon').to(Katana);
container.onActivation(
'Weapon',
(_context: interfaces.Context, katana: Katana): Katana | Promise<Katana> => {
katana.improve();
return katana;
},
);
// Katana.damage is 12
const katana: Weapon = container.get<Weapon>('Weapon');
onDeactivation
onDeactivation<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, onDeactivation: interfaces.BindingDeactivation<T>): void;
Adds a deactivation handler for a service identifier.
interface Weapon {
damage: number;
}
export class Katana implements Weapon {
readonly #damage: number = 10;
public get damage(): number {
return this.#damage;
}
}
const container: Container = new Container();
container.bind<Weapon>('Weapon').to(Katana).inSingletonScope();
container.get('Weapon');
container.onDeactivation('Weapon', (weapon: Weapon): void | Promise<void> => {
console.log(`Deactivating weapon with damage ${weapon.damage.toString()}`);
});
container.unbind('Weapon');
restore
restore(): void;
Restore container state to last snapshot. Refer to the docs for more information.
snapshot
snapshot(): void;
Save the state of the container to be later restored with the restore method. Refer to the docs for more information.
tryGet
tryGet<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T | undefined;
Same as container.get
, but returns undefined
in the event no bindings are bound to serviceIdentifier
.
tryGetAsync
tryGetAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): Promise<T | undefined>;
Same as container.getAsync
, but returns Promise<undefined>
in the event no bindings are bound to serviceIdentifier
.
tryGetNamed
tryGetNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T | undefined;
Same as container.getNamed
, but returns undefined
in the event no bindings are bound to serviceIdentifier
.
tryGetNamedAsync
tryGetNamedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): Promise<T | undefined>;
Same as container.getNamedAsync
, but returns Promise<undefined>
in the event no bindings are bound to serviceIdentifier
.
tryGetTagged
tryGetTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T | undefined;
Same as container.getTagged
, but returns undefined
in the event no bindings are bound to serviceIdentifier
.
tryGetTaggedAsync
tryGetTaggedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): Promise<T | undefined>
Same as container.getTaggedAsync
, but returns Promise<undefined>
in the event no bindings are bound to serviceIdentifier
.
tryGetAll
tryGetAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, options?: interfaces.GetAllOptions): T[]
Same as container.getAll
, but returns []
in the event no bindings are bound to serviceIdentifier
.
tryGetAllAsync
tryGetAllAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, options?: interfaces.GetAllOptions): Promise<T[]>;
Same as container.getAllAsync
, but returns Promise<[]>
in the event no bindings are bound to serviceIdentifier
.
tryGetAllNamed
tryGetAllNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T[];
Same as container.getAllNamed
, but returns []
in the event no bindings are bound to serviceIdentifier
.
tryGetAllNamedAsync
tryGetAllNamedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): Promise<T[]>;
Same as container.getAllNamedAsync
, but returns Promise<[]>
in the event no bindings are bound to serviceIdentifier
.
tryGetAllTagged
tryGetAllTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T[];
Same as container.getAllTagged
, but returns []
in the event no bindings are bound to serviceIdentifier
.
tryGetAllTaggedAsync
tryGetAllTaggedAsync<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): Promise<T[]>;
Same as container.getAllTaggedAsync
, but returns Promise<[]>
in the event no bindings are bound to serviceIdentifier
.
unbind
unbind(serviceIdentifier: interfaces.ServiceIdentifier): void;
Remove all bindings binded in this container to the service identifier. This will result in the deactivation process.
unbindAsync
unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): Promise<void>;
This is the asynchronous version of unbind. If any deactivation realated to this service identifier is asynchronous then this method should be used instead of container.unbind
.
unbindAll
unbindAll(): void;
Remove all bindings binded in this container. This will result in the deactivation process.
unbindAllAsync
unbindAllAsync(): Promise<void>;
This is the asynchronous version of unbindAll. If any of the container's deactivations is asynchronous then this method should be used instead of container.unbindAll
.
unload
unload(...modules: interfaces.ContainerModuleBase[]): void;
Removes bindings and handlers added by the modules. This will result in the deactivation process. See ContainerModule API docs.
unloadAsync
unloadAsync(...modules: interfaces.ContainerModuleBase[]): Promise<void>;
Asynchronous version of unload. If any of the container modules's deactivations is asynchronous then this method should be used instead of container.unload
.
parent
parent: Container | null;
Access the parent container.
id
id: number;
The container's unique identifier.