A lightweight dependency injection library for TypeScript applications.
Classes
- InjectableRegistryImp
Holds the various
Injectables in a cache and provides methods to register, retrieve, and build them.
Interfaces
- InjectablesRegistry
Interface for an injectable registry that provides methods for retrieving, registering, and building injectable objects.
Members
# static constant DefaultInjectablesConfig
Sets sensible defaults such as singleton lifecycle for newly registered injectables.
Default configuration applied by the @injectable decorator when none is provided.
# static constant InjectablesKeys
Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
Constants used for reflection metadata keys in the dependency injection system.
Properties:
| Name | Type | Description |
|---|---|---|
REFLECT |
string
|
Reflection injectables base key prefix for all metadata keys |
INJECTABLE |
string
|
Reflection key suffix for marking a class as injectable |
INJECT |
string
|
Reflection key suffix for marking a property for injection |
# static constant TypeKey
Holds the key for retrieving the design type from TypeScript's reflection metadata.
Reflection metadata key for accessing TypeScript type information.
# static constant VERSION
Defined on library build. Holds the library's current version string.
Current version of the injectable-decorators library.
# inner constant COMMIT
Stores the current git commit hash for the package. The build replaces the placeholder with the actual commit hash at publish time.
Represents the current commit hash of the module build.
# inner constant FULL_VERSION
Stores the semver version and commit hash for the package.
The build replaces the placeholder with the actual <version>-<commit> value at publish time.
Represents the full version string of the module.
Methods
# static getInjectKey(key) → {string}
Returns the reflection key for injectables by prefixing the provided key with the base reflection key.
Generates a fully qualified reflection metadata key.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string
|
The key to be prefixed |
The fully qualified reflection key
string
Type Definitions
object
# InjectOptions
Allows specifying constructor arguments and an optional transformer to be applied to the resolved instance.
Options for the property-level @inject decorator.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
Array.<any>
|
<optional> |
Optional constructor arguments to use when building the injectable instance. |
transformer |
InstanceTransformer
|
<optional> |
Optional function to transform the instance before assignment. |
args |
Array
|
<optional> |
|
transformer |
InstanceTransformer
|
<optional> |
# Injectable()
Defines an Injectable type that can be either a class constructor or an instance of a class.
Type representing either a class constructor or an instance.
Properties:
| Name | Type | Description |
|---|---|---|
...args: |
T
|
any[] |
object
# InjectableConfig
Controls lifecycle (singleton vs on-demand) and an optional instance transformation callback executed post-construction.
Configuration options for the @injectable decorator.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
singleton |
boolean
|
When true, a single instance is shared (singleton). When false, instances are created on demand. |
|
callback |
InstanceCallback.<T>
|
<optional> |
Optional hook to transform the instance after it is constructed. |
singleton |
boolean
|
||
callback |
InstanceCallback.<any>
|
<optional> |
object
# InjectableDef
Describes how the registry caches injectable metadata, constructor, and (optionally) a built instance.
Internal registry definition for a stored injectable entry.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
OPTS
|
The lifecycle/options associated with this injectable entry. |
|
instance |
*
|
<optional> |
The cached instance when applicable (e.g., singleton), otherwise undefined until built. |
constructor |
Constructor
|
The constructor used to create new instances. |
|
options |
OPTS
|
||
instance |
any
|
<optional> |
|
constructor |
Constructor.<T>
|
object
# InjectableMetadata
Captures identifying information stored via reflection for later retrieval and wiring.
Metadata attached to classes marked as injectable.
Properties:
| Name | Type | Description |
|---|---|---|
class |
string
|
The class name of the injectable. |
symbol |
symbol
|
The unique symbol under which the injectable is registered. |
class |
string
|
|
symbol |
symbol
|
object
# InjectableOptions
Specifies lifecycle and callback configuration for injectables, such as whether they are singletons and whether a post-build callback should run.
Options controlling how an injectable should be handled by the registry.
Properties:
| Name | Type | Description |
|---|---|---|
singleton |
boolean
|
Indicates if the injectable should be treated as a singleton (single shared instance). |
callback |
InstanceCallback.<T>
|
Optional callback invoked after building an instance to perform additional setup or transformation. |
singleton |
boolean
|
|
callback |
InstanceCallback.<T>
|
# InstanceCallback(instance, …args, instance, args) → {T}
Represents a post-construction hook that can modify or replace the created instance before it is returned to the caller.
Callback function type used to transform or initialize an instance after construction.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
instance |
T
|
The newly constructed instance. |
|
args |
any
|
<repeatable> |
Additional arguments forwarded from the construction context. |
instance |
T
|
||
args |
Array
|
The instance to be stored/returned, which may be the original or a transformed instance.
T
# InstanceTransformer(injectable, obj, injectable, obj) → {any}
Function which transforms a cached injectable instance before it's injected into a target object.
Function type for transforming injectable instances before they're injected.
Parameters:
| Name | Type | Description |
|---|---|---|
injectable |
any
|
The injectable instance to transform |
obj |
any
|
The object the injectable will be injected on |
injectable |
any
|
|
obj |
any
|
The transformed injectable instance
any