Skip to content

vue-mvvm / core / DIContainer

DIContainer ​

A container that manages dependency injection, including service registration, resolution, and provider components.

Implements ​

Constructors ​

Constructor ​

ts
new DIContainer(): DIContainer;

Returns ​

DIContainer

Methods ​

getProviders() ​

ts
getProviders(): Component[];

Retrieves all registered provider components.

Returns ​

Component[]

An array of registered provider components.

Implementation of ​

WritableGlobalContext.getProviders


getService() ​

Call Signature ​

ts
getService<T>(key): InstanceType<T>;

Retrieves a service instance by its constructor.

Type Parameters ​
T ​

T extends (...args) => any

Parameters ​
key ​

T

The constructor function of the service.

Returns ​

InstanceType<T>

The instance of the requested service.

Implementation of ​

WritableGlobalContext.getService

Call Signature ​

ts
getService<T>(key): T;

Retrieves a service instance by its ServiceKey.

Type Parameters ​
T ​

T

Parameters ​
key ​

ServiceKey<T>

The ServiceKey of the service.

Returns ​

T

The instance of the requested service.

Implementation of ​

WritableGlobalContext.getService

Call Signature ​

ts
getService<T>(key): Promise<T>;

Retrieves a service instance asynchronously by its AsyncServiceKey.

Type Parameters ​
T ​

T

Parameters ​
key ​

AsyncServiceKey<T>

The AsyncServiceKey of the service.

Returns ​

Promise<T>

A promise that resolves with the instance of the requested service.

Implementation of ​

WritableGlobalContext.getService


mockService() ​

Call Signature ​

ts
mockService<T>(key, handler): void;

Mocks a service by providing a custom implementation for the specified key.

Type Parameters ​
T ​

T

Parameters ​
key ​

ServiceKey<T>

The key used to identify the service to be mocked.

handler ​

FactoryFunction<T>

A factory function that provides the mocked behavior.

Returns ​

void

Implementation of ​

WritableGlobalContext.mockService

Call Signature ​

ts
mockService<T>(key, handler): void;

Mocks an asynchronous service by providing a custom implementation for the specified key.

Type Parameters ​
T ​

T

Parameters ​
key ​

AsyncServiceKey<T>

The key used to identify the service to be mocked.

handler ​

AsyncFactoryFunction<T>

An asynchronous factory function that provides the mocked behavior.

Returns ​

void

Implementation of ​

WritableGlobalContext.mockService

Call Signature ​

ts
mockService<T>(key, handler): void;

Mocks a service with a constructor key.

Type Parameters ​
T ​

T extends (...args) => any

Parameters ​
key ​

T

The constructor function used as the key.

handler ​

FactoryFunction<InstanceType<T>>

A factory function that provides the mocked behavior.

Returns ​

void

Implementation of ​

WritableGlobalContext.mockService


registerProvider() ​

ts
registerProvider(provider): void;

Registers a provider component.

Parameters ​

provider ​

Component

The Vue component to register as a provider.

Returns ​

void

Implementation of ​

WritableGlobalContext.registerProvider


registerService() ​

Call Signature ​

ts
registerService<T>(key, handler): void;

Registers a service with a specified key and factory function.

Type Parameters ​
T ​

T

Parameters ​
key ​

ServiceKey<T>

The key used to identify the service.

handler ​

FactoryFunction<T>

A factory function that creates an instance of the service.

Returns ​

void

Implementation of ​

WritableGlobalContext.registerService

Call Signature ​

ts
registerService<T>(key, handler): void;

Registers an asynchronous service with a specified key and factory function.

Type Parameters ​
T ​

T

Parameters ​
key ​

AsyncServiceKey<T>

The key used to identify the service.

handler ​

AsyncFactoryFunction<T>

An asynchronous factory function that creates an instance of the service.

Returns ​

void

Implementation of ​

WritableGlobalContext.registerService

Call Signature ​

ts
registerService<T>(key, handler): void;

Registers a service with a constructor key and factory function.

Type Parameters ​
T ​

T extends (...args) => any

Parameters ​
key ​

T

The constructor function used as the key.

handler ​

FactoryFunction<InstanceType<T>>

A factory function that creates an instance of the service.

Returns ​

void

Implementation of ​

WritableGlobalContext.registerService


toReadableGlobalContext() ​

ts
toReadableGlobalContext(): ReadableGlobalContext;

Creates a ReadableGlobalContext from this DIContainer instance.

Returns ​

ReadableGlobalContext

A read-only interface to the container.

Implementation of ​

WritableGlobalContext.toReadableGlobalContext