Methods
# inject(categoryopt, cfgopt) → {function}
Allows for the injection of an injectable
decorated dependency into a class property.
The property must be typed for the requested dependency. Only concrete classes are supported; generics are not.
Injected properties should be described like so:
class ClassName { ...Property decorator that injects a dependency into a class property.
sequenceDiagram participant Client participant Decorator participant Injectables Client->>Decorator: @inject() Decorator->>Decorator: Get type from property Decorator->>Decorator: Define metadata Decorator->>Decorator: Define property getter Note over Decorator: When property accessed Client->>Decorator: access property Decorator->>Decorator: Check if instance exists alt Instance exists in WeakMap Decorator-->>Client: Return cached instance else No instance Decorator->>Injectables: get(name) alt Injectable found Injectables-->>Decorator: Return injectable instance opt Has transformer Decorator->>Decorator: Call transformer end Decorator->>Decorator: Store in WeakMap Decorator-->>Client: Return instance else No injectable Decorator-->>Client: Throw error end endParameters:
Name Type Attributes Default Description category
string
<optional>
Defaults to the class name derived from the property type. Useful when minification occurs and names are changed, or when you want to upcast the object to a different type.
cfg
Partial.<InjectOptions>
<optional>
{} Optional function to transform the injectable instance before it's injected, or arguments to pass the constructor when injecting onDemand
A property decorator function that sets up the dependency injection.
function
# injectable(categoryopt, cfgopt) → {function}
Defines a class as an injectable that can be retrieved from the registry. When applied to a class, replaces its constructor with one that returns an instance.
Decorator that marks a class as available for dependency injection.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
category |
string
|
Constructor
|
<optional> |
Defaults to the class category. Useful when minification occurs and names are changed, or when you want to upcast the object to a different type. |
|
cfg |
Partial.<InjectableConfig>
|
<optional> |
DefaultInjectableConfig | Allows overriding the default singleton behavior and adding a callback function. |
A decorator function that transforms the class into an injectable.
function
# onDemand(categoryopt, cfgopt) → {function}
Wraps injectable
forcing new instances to be created on every injection or retrieval.
Convenience decorator to register an injectable as on-demand (non-singleton).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
category |
string
|
Constructor
|
<optional> |
Optional explicit category/symbol source; defaults to the class. |
cfg |
Omit.<InjectableConfig, "singleton">
|
<optional> |
Additional injectable configuration excluding the singleton flag. |
A class decorator that registers the target as a non-singleton injectable.
function
# singleton(categoryopt, cfgopt) → {function}
Wraps injectable
forcing the singleton lifecycle so only one instance is created and reused.
Convenience decorator to register an injectable as a singleton.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
category |
string
|
Constructor
|
<optional> |
Optional explicit category/symbol source; defaults to the class. |
cfg |
Omit.<InjectableConfig, "singleton">
|
<optional> |
Additional injectable configuration excluding the singleton flag. |
A class decorator that registers the target as a singleton injectable.
function