Global

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 end
Parameters:
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

View Source decorators.ts, line 165

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.

sequenceDiagram participant Client participant Decorator participant Injectables Client->>Decorator: @injectable() Decorator->>Decorator: Create new constructor Note over Decorator: When new instance requested Decorator->>Injectables: get(category) alt Instance exists Injectables-->>Decorator: Return existing instance else No instance Decorator->>Injectables: register(original, category) Decorator->>Injectables: get(category) Injectables-->>Decorator: Return new instance opt Has callback Decorator->>Decorator: Call instanceCallback end end Decorator->>Decorator: Define metadata Decorator-->>Client: Return instance
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.

View Source decorators.ts, line 48

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.

View Source decorators.ts, line 103

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.

View Source decorators.ts, line 91

A class decorator that registers the target as a singleton injectable.

function