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

Parameter Description
TMap

Constructors

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

Properties

Property Type Description
IFluidDependencySynthesizer this

Methods

Method Return Type Description
has(type, excludeParents) boolean Check if a given type is registered
register(type, provider) void Add 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) void Remove a provider

Constructor Details

(constructor)

Constructs a new instance of the DependencyContainer class

Signature

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

Parameters

Parameter Type Description
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

Parameter Modifiers Type Description
type string Type to check
excludeParents optional boolean

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
Parameter Default Description
T keyof TMap

Parameters

Parameter Type Description
type T Name of the Type T being provided
provider FluidObjectProvider<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
Parameter Default Description
O
R undefined | Record<string, never>

Parameters

Parameter Type Description
optionalTypes FluidObjectSymbolProvider<O> optional types to be in the Scope object
requiredTypes Required<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

Parameter Type Description
type keyof TMap Name of the provider to remove