Skip to main content
Version: v1

DependencyContainer Class

DependencyContainer is similar to a IoC Container. It takes providers and will synthesize an object based on them when requested.

Signature​

export declare class DependencyContainer<TMap> implements IFluidDependencySynthesizer

Implements: IFluidDependencySynthesizer

Type Parameters​

ParameterDescription
TMap

Constructors​

ConstructorDescription
(constructor)(parents)Constructs a new instance of the DependencyContainer class

Properties​

PropertyTypeDescription
IFluidDependencySynthesizerthis

Methods​

MethodReturn TypeDescription
has(type, excludeParents)booleanCheck if a given type is registered
register(type, provider)voidAdd a new provider
synthesize(optionalTypes, requiredTypes)AsyncFluidObjectProvider<O, R>synthesize takes optional and required types and returns an object that will fulfill the defined types based off objects that has been previously registered.
unregister(type)voidRemove a provider

Constructor Details​

(constructor)​

Constructs a new instance of the DependencyContainer class

Signature​

constructor(...parents: (IFluidDependencySynthesizer | undefined)[]);

Parameters​

ParameterTypeDescription
parents(IFluidDependencySynthesizer | undefined)[]

Property Details​

IFluidDependencySynthesizer​

Signature​

get IFluidDependencySynthesizer(): this;

Type: this

Method Details​

has​

Check if a given type is registered

Signature​

has(type: string, excludeParents?: boolean): boolean;

Parameters​

ParameterModifiersTypeDescription
typestringType to check
excludeParentsoptionalboolean

Returns​

Return type: boolean

register​

Add a new provider

Signature​

register<T extends keyof TMap = keyof TMap>(type: T, provider: FluidObjectProvider<Pick<TMap, T>>): void;
Type Parameters​
ParameterDefaultDescription
Tkeyof TMap

Parameters​

ParameterTypeDescription
typeTName of the Type T being provided
providerFluidObjectProvider<Pick<TMap, T>>A provider that will resolve the T correctly when asked

Error Handling​

  • If passing a type that's already registered

synthesize​

synthesize takes optional and required types and returns an object that will fulfill the defined types based off objects that has been previously registered.

Signature​

synthesize<O, R = undefined | Record<string, never>>(optionalTypes: FluidObjectSymbolProvider<O>, requiredTypes: Required<FluidObjectSymbolProvider<R>>): AsyncFluidObjectProvider<O, R>;
Type Parameters​
ParameterDefaultDescription
O
Rundefined | Record<string, never>

Parameters​

ParameterTypeDescription
optionalTypesFluidObjectSymbolProvider<O>optional types to be in the Scope object
requiredTypesRequired<FluidObjectSymbolProvider<R>>required types that need to be in the Scope object

Returns​

Return type: AsyncFluidObjectProvider<O, R>

unregister​

Remove a provider

Signature​

unregister(type: keyof TMap): void;

Parameters​

ParameterTypeDescription
typekeyof TMapName of the provider to remove