DIContainer
A container that manages dependency injection, including service registration, resolution, and provider components.
Implements
Constructors
Constructor
new DIContainer(): DIContainer;Returns
DIContainer
Methods
getProviders()
getProviders(): Component[];Retrieves all registered provider components.
Returns
Component[]
An array of registered provider components.
Implementation of
WritableGlobalContext.getProviders
getService()
Call Signature
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
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
getService<T>(key): Promise<T>;Retrieves a service instance asynchronously by its AsyncServiceKey.
Type Parameters
T
T
Parameters
key
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
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
A factory function that provides the mocked behavior.
Returns
void
Implementation of
WritableGlobalContext.mockService
Call Signature
mockService<T>(key, handler): void;Mocks an asynchronous service by providing a custom implementation for the specified key.
Type Parameters
T
T
Parameters
key
The key used to identify the service to be mocked.
handler
An asynchronous factory function that provides the mocked behavior.
Returns
void
Implementation of
WritableGlobalContext.mockService
Call Signature
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()
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
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
A factory function that creates an instance of the service.
Returns
void
Implementation of
WritableGlobalContext.registerService
Call Signature
registerService<T>(key, handler): void;Registers an asynchronous service with a specified key and factory function.
Type Parameters
T
T
Parameters
key
The key used to identify the service.
handler
An asynchronous factory function that creates an instance of the service.
Returns
void
Implementation of
WritableGlobalContext.registerService
Call Signature
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()
toReadableGlobalContext(): ReadableGlobalContext;Creates a ReadableGlobalContext from this DIContainer instance.
Returns
A read-only interface to the container.