# new Injectables()
Static class holding the access to the injectables functions. Provides methods for registering, retrieving, and building injectable objects.
Central registry for managing injectable dependencies.
Example
// Define an injectable class
Methods
# static build(obj, args) → {T}
Instantiates an injectable class using its constructor and the provided arguments.
Creates a new instance of an injectable class.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Record.<string, any>
|
Object containing the name of the injectable to build |
args |
Array.<any>
|
Constructor arguments to pass when instantiating the injectable |
The newly created instance
T
# static get(name, args) → {Injectable.<T>|undefined}
Retrieves the named Injectable
from the registry. If the injectable is a singleton,
returns the existing instance. Otherwise, creates a new instance.
Fetches an injectable instance by its registered name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
The registered name of the injectable to retrieve |
args |
Array.<any>
|
Constructor arguments to pass when instantiating the injectable |
The injectable instance or undefined if not found
Injectable.<T>
|
undefined
# static getRegistry() → {InjectablesRegistry}
Returns the current InjectablesRegistry
or creates a default one if none exists.
Provides access to the current registry instance.
The current registry instance
InjectablesRegistry
# static register(constructor, args) → {void}
Registers an injectable constructor or instance with the registry, making it available for injection.
Adds a class or object to the injectable registry.
Parameters:
Name | Type | Description |
---|---|---|
constructor |
Injectable.<T>
|
The class constructor or object instance to register |
args |
Array.<any>
|
Additional arguments for registration (category, singleton flag, etc.) |
void
# static reset() → {void}
Resets the registry to a clean state by creating a new empty registry instance.
Clears all registered injectables.
void
# static selectiveReset(match) → {void}
Selectively resets the registry by removing only the injectables whose names match the provided pattern.
Removes specific injectables from the registry based on a pattern.
Parameters:
Name | Type | Description |
---|---|---|
match |
string
|
RegExp
|
A string or regular expression pattern to match against injectable names |
void
# static setRegistry(operationsRegistry) → {void}
Sets a new InjectablesRegistry
implementation, allowing for custom registry behavior.
Replaces the current registry implementation.
Parameters:
Name | Type | Description |
---|---|---|
operationsRegistry |
InjectablesRegistry
|
The new implementation of Registry to use |
void