aurelia-dependency-injection

  • Version 1.6.1
  • Published
  • 1.49 MB
  • 2 dependencies
  • MIT license

Install

npm i aurelia-dependency-injection
yarn add aurelia-dependency-injection
pnpm add aurelia-dependency-injection

Overview

A lightweight, extensible dependency injection container for JavaScript.

Index

Variables

variable resolver

const resolver: {
decorates?: (key: any) => key is { get(container: Container, key: any): any };
} & (() => any);
  • Decorator: Indicates that the decorated class/object is a custom resolver.

Functions

function all

all: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
keyValue: any
) => (
target: DependencyCtor<TBase, TImpl, TArgs> & { inject?: TArgs[number][] },
_key: any,
index: number
) => void;
  • Decorator: Specifies the dependency should load all instances of the given key.

function autoinject

autoinject: <TPotential>(
potentialTarget?: TPotential
) => TPotential extends Injectable ? void : (target: Injectable) => void;
  • Decorator: Directs the TypeScript transpiler to write-out type metadata for the decorated class.

function factory

factory: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
keyValue: any
) => (
target: DependencyCtor<TBase, TImpl, TArgs> & { inject?: TArgs[number][] },
_key: any,
index: number
) => void;
  • Decorator: Specifies the dependency to create a factory method, that can accept optional arguments

function getDecoratorDependencies

getDecoratorDependencies: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
target: DependencyCtor<TBase, TImpl, TArgs> & { inject?: TArgs[number][] }
) => TArgs[number][] | undefined;
  • Used by parameter decorators to call autoinject for the target and retrieve the target's inject property.

    Parameter target

    The target class. Returns the target's own inject property.

function inject

inject: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
...rest: TArgs[number][]
) => any;
  • Decorator: Specifies the dependencies that should be injected by the DI Container into the decorated class/function.

function invokeAsFactory

invokeAsFactory: <TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(
potentialTarget?: DependencyCtor<TBase, TImpl, TArgs>
) => void | ((target: DependencyCtor<TBase, TImpl, TArgs>) => void);
  • Decorator: Specifies that the decorated item should be called as a factory function, rather than a constructor.

function invoker

invoker: <TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(
value: Invoker<TBase, TImpl, TArgs>
) => (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
  • Decorator: Specifies a custom Invoker for the decorated item.

function lazy

lazy: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
keyValue: any
) => (
target: new (...args: TArgs) => TBase | TImpl,
_key: any,
index: number
) => void;
  • Decorator: Specifies the dependency should be lazy loaded

function newInstance

newInstance: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
asKeyOrTarget?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
},
...dynamicDependencies: TArgs[number][]
) => (target: new (...args: any[]) => any, _key: any, index: number) => void;
  • Decorator: Specifies the dependency as a new instance. Instances can optionally be registered in the container under a different key and/or use dynamic dependencies

function optional

optional: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
checkParentOrTarget?: boolean
) => (
target: DependencyCtor<TBase, TImpl, TArgs> & { inject?: TArgs[number][] },
_key: any,
index: number
) => void;
  • Decorator: Specifies the dependency as optional

function parent

parent: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
target: DependencyCtor<TBase, TImpl, TArgs> & { inject?: TArgs[number][] },
_key: any,
index: number
) => void;
  • Decorator: Specifies the dependency to look at the parent container for resolution

function registration

registration: <TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(
value: Registration<TBase, TImpl, TArgs>
) => (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
  • Decorator: Specifies a custom registration strategy for the decorated class/function.

function resolve

resolve: {
<K extends unknown>(key: K): ResolvedValue<K>;
<K extends any[]>(...keys: K): ResolvedValue<K>;
};
  • Resolve a key, or list of keys based on the current container.

    Example 1

    import { resolve } from 'aurelia-framework';
    // or
    // import { Container, resolve } from 'aurelia-dependency-injection';
    class MyCustomElement {
    someService = resolve(MyService);
    }

function singleton

singleton: {
(registerInChild?: boolean): any;
<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(
key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
registerInChild?: boolean
): any;
};
  • Decorator: Specifies to register the decorated item with a "singleton" lifetime.

function transient

transient: <TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(
key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
  • Decorator: Specifies to register the decorated item with a "transient" lifetime.

Classes

class All

class All<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to allow functions/classes to specify resolution of all matches to a key.

constructor

constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
  • Creates an instance of the All class.

    Parameter key

    The key to lazily resolve all matches for.

method get

get: (container: Container) => TImpl[];
  • Called by the container to resolve all matching dependencies as an array of instances.

    Parameter container

    The container to resolve from. Returns an array of all matching instances.

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => All<TBase, TImpl, TArgs>;
  • Creates an All Resolver for the supplied key.

    Parameter key

    The key to resolve all instances for. Returns an instance of All for the key.

class Container

class Container {}
  • A lightweight, extensible dependency injection container.

constructor

constructor(configuration?: ContainerConfiguration);
  • Creates an instance of Container.

    Parameter configuration

    Provides some configuration for the new Container instance.

property instance

static instance: Container;
  • The global root Container instance. Available if makeGlobal() has been called. Aurelia Framework calls makeGlobal().

property parent

parent: Container;
  • The parent container in the DI hierarchy.

property root

root: Container;
  • The root container in the DI hierarchy.

method autoRegister

autoRegister: {
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: Primitive,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: DependencyCtor<TBase, TImpl, TArgs>,
fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
};
  • Registers a type (constructor function) by inspecting its registration annotations. If none are found, then the default singleton registration is used.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter fn

    The constructor function to use when the dependency needs to be instantiated. This defaults to the key value when fn is not supplied.

method autoRegisterAll

autoRegisterAll: (fns: DependencyCtor<any, any, any>[]) => void;
  • Registers an array of types (constructor functions) by inspecting their registration annotations. If none are found, then the default singleton registration is used.

    Parameter fns

    The constructor function to use when the dependency needs to be instantiated.

method createChild

createChild: () => Container;
  • Creates a new dependency injection container whose parent is the current container. Returns a new container instance parented to this.

method get

get: {
<
TBase,
TResolver extends
| NewInstance<TBase, Impl<TBase>, Args<TBase>>
| Lazy<TBase, Impl<TBase>, Args<TBase>>
| Factory<TBase, Impl<TBase>, Args<TBase>>
| Optional<TBase, Impl<TBase>, Args<TBase>>
| Parent<TBase, Impl<TBase>, Args<TBase>>
| All<TBase, Impl<TBase>, Args<TBase>>
>(
key: TResolver
): ResolvedValue<TResolver>;
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
): ImplOrAny<TImpl>;
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: typeof Container
): Container;
};
  • Resolves a single instance based on the provided key.

    Parameter key

    The key that identifies the object to resolve. Returns the resolved instance.

method getAll

getAll: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => ImplOrAny<TImpl>[];
  • Resolves all instance registered under the provided key.

    Parameter key

    The key that identifies the objects to resolve. Returns an array of the resolved instances.

method getResolver

getResolver: <
TStrategyKey extends keyof StrategyState<TBase, TImpl, TArgs>,
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>
) => StrategyResolver<TBase, TImpl, TArgs, TStrategyKey>;
  • Gets the resolver for the particular key, if it has been registered.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function. Returns the resolver, if registred, otherwise undefined.

method hasResolver

hasResolver: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
checkParent?: boolean
) => boolean;
  • Inspects the container to determine if a particular key has been registred.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter checkParent

    Indicates whether or not to check the parent container hierarchy. Returns true if the key has been registred; false otherwise.

method invoke

invoke: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
dynamicDependencies?: TArgs[number][]
) => ImplOrAny<TImpl>;
  • Invokes a function, recursively resolving its dependencies.

    Parameter fn

    The function to invoke with the auto-resolved dependencies.

    Parameter dynamicDependencies

    Additional function dependencies to use during invocation. Returns the instance resulting from calling the function.

method makeGlobal

makeGlobal: () => Container;
  • Makes this container instance globally reachable through Container.instance.

method registerAlias

registerAlias: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
originalKey: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
aliasKey: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => Resolver;
  • Registers an additional key that serves as an alias to the original DI key.

    Parameter originalKey

    The key that originally identified the dependency; usually a constructor function.

    Parameter aliasKey

    An alternate key which can also be used to resolve the same dependency as the original. The resolver that was registered.

method registerHandler

registerHandler: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
handler: (
container?: Container,
key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
resolver?: Resolver
) => any
) => Resolver;
  • Registers a custom resolution function such that the container calls this function for each request to obtain the instance.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter handler

    The resolution function to use when the dependency is needed. The resolver that was registered.

method registerInstance

registerInstance: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
instance?: TImpl
) => Resolver;
  • Registers an existing object instance with the container.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter instance

    The instance that will be resolved when the key is matched. This defaults to the key value when instance is not supplied. The resolver that was registered.

method registerResolver

registerResolver: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
resolver: Resolver
) => Resolver;
  • Registers a custom resolution function such that the container calls this function for each request to obtain the instance.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter resolver

    The resolver to use when the dependency is needed. The resolver that was registered.

method registerSingleton

registerSingleton: {
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: Primitive,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: DependencyCtor<TBase, TImpl, TArgs>,
fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
};
  • Registers a type (constructor function) such that the container always returns the same instance for each request.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter fn

    The constructor function to use when the dependency needs to be instantiated. This defaults to the key value when fn is not supplied. The resolver that was registered.

method registerTransient

registerTransient: {
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: Primitive,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: DependencyCtor<TBase, TImpl, TArgs>,
fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
): Resolver;
};
  • Registers a type (constructor function) such that the container returns a new instance for each request.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

    Parameter fn

    The constructor function to use when the dependency needs to be instantiated. This defaults to the key value when fn is not supplied. The resolver that was registered.

method setHandlerCreatedCallback

setHandlerCreatedCallback: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
onHandlerCreated: (
handler: InvocationHandler<TBase, TImpl, TArgs>
) => InvocationHandler<TBase, TImpl, TArgs>
) => void;
  • Sets an invocation handler creation callback that will be called when new InvocationsHandlers are created (called once per Function).

    Parameter onHandlerCreated

    The callback to be called when an InvocationsHandler is created.

method unregister

unregister: (key: any) => void;
  • Unregisters based on key.

    Parameter key

    The key that identifies the dependency at resolution time; usually a constructor function.

class Factory

class Factory<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to allow injecting dependencies but also passing data to the constructor.

constructor

constructor(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>);
  • Creates an instance of the Factory class.

    Parameter key

    The key to resolve from the parent container.

method get

get: (container: Container) => DependencyFunctor<TBase, TImpl, TArgs>;
  • Called by the container to pass the dependencies to the constructor.

    Parameter container

    The container to invoke the constructor with dependencies and other parameters. Returns a function that can be invoked to resolve dependencies later, and the rest of the parameters.

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: DependencyCtor<TBase, TImpl, TArgs>
) => Factory<TBase, TImpl, TArgs>;
  • Creates a Factory Resolver for the supplied key.

    Parameter key

    The key to resolve. Returns an instance of Factory for the key.

class FactoryInvoker

class FactoryInvoker<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> implements Invoker<TBase, TImpl, TArgs> {}
  • An Invoker that is used to invoke a factory method.

property instance

static instance: FactoryInvoker<any, any, Args<any>>;
  • The singleton instance of the FactoryInvoker.

method invoke

invoke: (
container: Container,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
dependencies: TArgs
) => ImplOrAny<TImpl>;
  • Invokes the function with the provided dependencies.

    Parameter container

    The calling container.

    Parameter fn

    The constructor or factory function.

    Parameter dependencies

    The dependencies of the function call. The result of the function invocation.

method invokeWithDynamicDependencies

invokeWithDynamicDependencies: (
container: Container,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
staticDependencies: TArgs[number][],
dynamicDependencies: TArgs[number][]
) => ImplOrAny<TImpl>;
  • Invokes the function with the provided dependencies.

    Parameter container

    The calling container.

    Parameter fn

    The constructor or factory function.

    Parameter staticDependencies

    The static dependencies of the function.

    Parameter dynamicDependencies

    Additional dependencies to use during invocation. The result of the function invocation.

class InvocationHandler

class InvocationHandler<
TBase,
TImpl extends Impl<TBase>,
TArgs extends Args<TBase>
> {}
  • Stores the information needed to invoke a function.

constructor

constructor(
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
invoker: Invoker<TBase, TImpl, TArgs>,
dependencies: any[] | unknown[]
);
  • Instantiates an InvocationDescription.

    Parameter fn

    The Function described by this description object.

    Parameter invoker

    The strategy for invoking the function.

    Parameter dependencies

    The static dependencies of the function call.

property dependencies

dependencies: any[] | unknown[];
  • The statically known dependencies of this function invocation.

property fn

fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;
  • The function to be invoked by this handler.

property invoker

invoker: Invoker<TBase, TImpl, TArgs>;
  • The invoker implementation that will be used to actually invoke the function.

method invoke

invoke: (container: Container, dynamicDependencies?: TArgs[]) => TImpl;
  • Invokes the function.

    Parameter container

    The calling container.

    Parameter dynamicDependencies

    Additional dependencies to use during invocation. The result of the function invocation.

class Lazy

class Lazy<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to allow functions/classes to specify lazy resolution logic.

constructor

constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
  • Creates an instance of the Lazy class.

    Parameter key

    The key to lazily resolve.

method get

get: (container: Container) => () => ImplOrAny<TImpl>;
  • Called by the container to lazily resolve the dependency into a lazy locator function.

    Parameter container

    The container to resolve from. Returns a function which can be invoked at a later time to obtain the actual dependency.

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => Lazy<TBase, TImpl, TArgs>;
  • Creates a Lazy Resolver for the supplied key.

    Parameter key

    The key to lazily resolve. Returns an instance of Lazy for the key.

class NewInstance

class NewInstance<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to inject a new instance of a dependency, without regard for existing instances in the container. Instances can optionally be registered in the container under a different key by supplying a key using the as method.

constructor

constructor(
key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>,
...dynamicDependencies: TArgs[number][]
);
  • Creates an instance of the NewInstance class.

    Parameter key

    The key to resolve/instantiate.

    Parameter dynamicDependencies

    An optional list of dynamic dependencies.

method as

as: (key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>) => this;
  • Instructs the NewInstance resolver to register the resolved instance using the supplied key.

    Parameter key

    The key to register the instance with. Returns the NewInstance resolver.

method get

get: (container: Container) => ImplOrAny<TImpl>;
  • Called by the container to instantiate the dependency and potentially register as another key if the as method was used.

    Parameter container

    The container to resolve the parent from. Returns the matching instance from the parent container

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>,
...dynamicDependencies: TArgs[number][]
) => NewInstance<TBase, TImpl, TArgs>;
  • Creates an NewInstance Resolver for the supplied key.

    Parameter key

    The key to resolve/instantiate.

    Parameter dynamicDependencies

    An optional list of dynamic dependencies. Returns an instance of NewInstance for the key.

class Optional

class Optional<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to allow functions/classes to specify an optional dependency, which will be resolved only if already registred with the container.

constructor

constructor(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
checkParent?: boolean
);
  • Creates an instance of the Optional class.

    Parameter key

    The key to optionally resolve for.

    Parameter checkParent

    Indicates whether or not the parent container hierarchy should be checked.

method get

get: (container: Container) => TImpl | null;
  • Called by the container to provide optional resolution of the key.

    Parameter container

    The container to resolve from. Returns the instance if found; otherwise null.

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
checkParent?: boolean
) => Optional<TBase, TImpl, TArgs>;
  • Creates an Optional Resolver for the supplied key.

    Parameter key

    The key to optionally resolve for.

    Parameter checkParent

    Indicates whether or not the parent container hierarchy should be checked. Returns an instance of Optional for the key.

class Parent

class Parent<
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
> {}
  • Used to inject the dependency from the parent container instead of the current one.

constructor

constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
  • Creates an instance of the Parent class.

    Parameter key

    The key to resolve from the parent container.

method get

get: (container: Container) => TImpl | null;
  • Called by the container to load the dependency from the parent container

    Parameter container

    The container to resolve the parent from. Returns the matching instance from the parent container

method of

static of: <
TBase,
TImpl extends Impl<TBase> = Impl<TBase>,
TArgs extends Args<TBase> = Args<TBase>
>(
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
) => Parent<TBase, TImpl, TArgs>;
  • Creates a Parent Resolver for the supplied key.

    Parameter key

    The key to resolve. Returns an instance of Parent for the key.

class SingletonRegistration

class SingletonRegistration<
TBase,
TImpl extends Impl<TBase>,
TArgs extends Args<TBase>
> implements Registration<TBase, TImpl, TArgs> {}
  • Used to allow functions/classes to indicate that they should be registered as singletons with the container.

constructor

constructor(
keyOrRegisterInChild?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
registerInChild?: boolean
);
  • Creates an instance of SingletonRegistration.

    Parameter key

    The key to register as.

method registerResolver

registerResolver: (
container: Container,
key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
) => Resolver;
  • Called by the container to register the resolver.

    Parameter container

    The container the resolver is being registered with.

    Parameter key

    The key the resolver should be registered as.

    Parameter fn

    The function to create the resolver for. The resolver that was registered.

class StrategyResolver

class StrategyResolver<
TBase,
TImpl extends Impl<TBase>,
TArgs extends Args<TBase>,
TStrategyKey extends keyof StrategyState<TBase, TImpl, TArgs>
> {}
  • Used to resolve instances, singletons, transients, aliases

constructor

constructor(strategy: keyof StrategyState<TBase, TImpl, TArgs>, state: any);
  • Creates an instance of the StrategyResolver class.

    Parameter strategy

    The type of resolution strategy.

    Parameter state

    The state associated with the resolution strategy.

property state

state: any;

    property strategy

    strategy: keyof StrategyState<TBase, TImpl, TArgs>;

      method get

      get: (
      container: Container,
      key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
      ) => TImpl;
      • Called by the container to allow custom resolution of dependencies for a function/class.

        Parameter container

        The container to resolve from.

        Parameter key

        The key that the resolver was registered as. Returns the resolved object.

      class TransientRegistration

      class TransientRegistration<
      TBase,
      TImpl extends Impl<TBase>,
      TArgs extends Args<TBase>
      > implements Registration<TBase, TImpl, TArgs> {}
      • Used to allow functions/classes to indicate that they should be registered as transients with the container.

      constructor

      constructor(key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
      • Creates an instance of TransientRegistration.

        Parameter key

        The key to register as.

      method registerResolver

      registerResolver: (
      container: Container,
      key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
      fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
      ) => Resolver;
      • Called by the container to register the resolver.

        Parameter container

        The container the resolver is being registered with.

        Parameter key

        The key the resolver should be registered as.

        Parameter fn

        The function to create the resolver for. The resolver that was registered.

      Interfaces

      interface ContainerConfiguration

      interface ContainerConfiguration {}
      • Used to configure a Container instance.

      property handlers

      handlers?: Map<any, any>;

        property onHandlerCreated

        onHandlerCreated?: (
        handler: InvocationHandler<any, any, any>
        ) => InvocationHandler<any, any, any>;
        • An optional callback which will be called when any function needs an InvocationHandler created (called once per Function).

        interface Invoker

        interface Invoker<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> {}
        • A strategy for invoking a function, resulting in an object instance.

        method invoke

        invoke: (
        container: Container,
        fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
        dependencies: TArgs
        ) => ImplOrAny<TImpl>;
        • Invokes the function with the provided dependencies.

          Parameter fn

          The constructor or factory function.

          Parameter dependencies

          The dependencies of the function call. The result of the function invocation.

        method invokeWithDynamicDependencies

        invokeWithDynamicDependencies: (
        container: Container,
        fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>,
        staticDependencies: TArgs[number][],
        dynamicDependencies: TArgs[number][]
        ) => ImplOrAny<TImpl>;
        • Invokes the function with the provided dependencies.

          Parameter fn

          The constructor or factory function.

          Parameter staticDependencies

          The static dependencies of the function.

          Parameter dynamicDependencies

          Additional dependencies to use during invocation. The result of the function invocation.

        interface Registration

        interface Registration<
        TBase,
        TImpl extends Impl<TBase>,
        TArgs extends Args<TBase>
        > {}
        • Customizes how a particular function is resolved by the Container.

        method registerResolver

        registerResolver: (
        container: Container,
        key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>,
        fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>
        ) => Resolver;
        • Called by the container to register the resolver.

          Parameter container

          The container the resolver is being registered with.

          Parameter key

          The key the resolver should be registered as.

          Parameter fn

          The function to create the resolver for. The resolver that was registered.

        interface Resolver

        interface Resolver {}
        • Used to allow functions/classes to specify custom dependency resolution logic.

        method get

        get: (container: Container, key: any) => any;
        • Called by the container to allow custom resolution of dependencies for a function/class.

          Parameter container

          The container to resolve from.

          Parameter key

          The key that the resolver was registered as. Returns the resolved object.

        interface StrategyState

        interface StrategyState<
        TBase,
        TImpl extends Impl<TBase> = Impl<TBase>,
        TArgs extends Args<TBase> = Args<TBase>
        > {}

          property [Strategy.alias]

          [Strategy.alias]: any;

            property [Strategy.array]

            [Strategy.array]: (
            | {
            get: (
            container: Container,
            key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>
            ) => TImpl;
            }
            | TImpl
            )[];
            • For typings purposes, this is done as ({ get: StrategyFunctor } | TImpl)[] But it should be understood, and used as [{ get: StrategyFunctor }, ...TImp[]]

            property [Strategy.function]

            [Strategy.function]: StrategyFunctor<TBase, TImpl, TArgs>;

              property [Strategy.instance]

              [Strategy.instance]: TImpl;

                property [Strategy.singleton]

                [Strategy.singleton]: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;

                  property [Strategy.transient]

                  [Strategy.transient]: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;

                    Enums

                    enum Strategy

                    enum Strategy {
                    instance = 0,
                    singleton = 1,
                    transient = 2,
                    function = 3,
                    array = 4,
                    alias = 5,
                    }

                      member alias

                      alias = 5

                        member array

                        array = 4

                          member function

                          function = 3

                            member instance

                            instance = 0

                              member singleton

                              singleton = 1

                                member transient

                                transient = 2

                                  Type Aliases

                                  type Args

                                  type Args<TBase> = CtorArgs<TBase> | FuncArgs<TBase>;

                                    type CtorArgs

                                    type CtorArgs<TBase> = TBase extends new (...args: infer TArgs) => infer Impl
                                    ? TArgs
                                    : any[];

                                      type CtorImpl

                                      type CtorImpl<TBase> = TBase extends new (...args: infer TArgs) => infer Impl
                                      ? Impl
                                      : any;

                                        type DependencyCtor

                                        type DependencyCtor<
                                        TBase,
                                        TImpl extends Impl<TBase> = Impl<TBase>,
                                        TArgs extends Args<TBase> = Args<TBase>
                                        > = new (...args: TArgs) => TImpl | TBase;

                                          type DependencyCtorOrFunctor

                                          type DependencyCtorOrFunctor<
                                          TBase,
                                          TImpl extends Impl<TBase> = Impl<TBase>,
                                          TArgs extends Args<TBase> = Args<TBase>
                                          > = DependencyCtor<TBase, TImpl, TArgs> | DependencyFunctor<TBase, TImpl, TArgs>;

                                            type DependencyFunctor

                                            type DependencyFunctor<
                                            TBase,
                                            TImpl extends Impl<TBase> = Impl<TBase>,
                                            TArgs extends Args<TBase> = Args<TBase>
                                            > = (...args: TArgs) => TImpl | TBase;

                                              type FuncArgs

                                              type FuncArgs<TBase> = TBase extends (...args: infer TArgs) => infer Impl
                                              ? TArgs
                                              : any[];

                                                type FuncReturns

                                                type FuncReturns<TBase> = TBase extends (...args: infer TArgs) => infer Impl
                                                ? Impl
                                                : any;

                                                  type Impl

                                                  type Impl<TBase> = CtorImpl<TBase> | FuncReturns<TBase>;

                                                    type ImplOrAny

                                                    type ImplOrAny<TImpl> = unknown extends TImpl ? any : TImpl;

                                                      type Injectable

                                                      type Injectable = Function & {
                                                      inject?: any[] | (() => any[]);
                                                      };

                                                        type IStrategy

                                                        type IStrategy = 1 | 2 | 3 | 4 | 5;

                                                          type Primitive

                                                          type Primitive =
                                                          | boolean
                                                          | string
                                                          | number
                                                          | symbol
                                                          | object
                                                          | ((...args: any[]) => any)
                                                          | Array<any>;

                                                            type PrimitiveOrDependencyCtor

                                                            type PrimitiveOrDependencyCtor<
                                                            TBase,
                                                            TImpl extends Impl<TBase> = Impl<TBase>,
                                                            TArgs extends Args<TBase> = Args<TBase>
                                                            > = DependencyCtor<TBase, TImpl, TArgs> | Primitive;

                                                              type PrimitiveOrDependencyCtorOrFunctor

                                                              type PrimitiveOrDependencyCtorOrFunctor<
                                                              TBase,
                                                              TImpl extends Impl<TBase> = Impl<TBase>,
                                                              TArgs extends Args<TBase> = Args<TBase>
                                                              > =
                                                              | DependencyCtor<TBase, TImpl, TArgs>
                                                              | DependencyFunctor<TBase, TImpl, TArgs>
                                                              | Primitive;

                                                                type ResolvedValue

                                                                type ResolvedValue<T> = T extends new (...args: any[]) => infer R
                                                                ? R
                                                                : T extends abstract new (...args: any[]) => infer R
                                                                ? R
                                                                : T extends Factory<infer R>
                                                                ? (...args: unknown[]) => R
                                                                : T extends Lazy<infer R>
                                                                ? () => R
                                                                : T extends NewInstance<infer R>
                                                                ? R
                                                                : T extends Optional<infer R>
                                                                ? R | null
                                                                : T extends All<infer R>
                                                                ? R[]
                                                                : T extends Parent<infer R>
                                                                ? R | null
                                                                : T extends [infer T1, ...infer T2]
                                                                ? [ResolvedValue<T1>, ...ResolvedValue<T2>]
                                                                : T;

                                                                  type StrategyFunctor

                                                                  type StrategyFunctor<
                                                                  TBase,
                                                                  TImpl extends Impl<TBase> = Impl<TBase>,
                                                                  TArgs extends Args<TBase> = Args<TBase>
                                                                  > = (
                                                                  container?: Container,
                                                                  ctor?: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>,
                                                                  strategyResolver?: any
                                                                  ) => TImpl;

                                                                    Package Files (1)

                                                                    Dependencies (2)

                                                                    Dev Dependencies (16)

                                                                    Peer Dependencies (0)

                                                                    No peer dependencies.

                                                                    Badge

                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/aurelia-dependency-injection.

                                                                    • Markdown
                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/aurelia-dependency-injection)
                                                                    • HTML
                                                                      <a href="https://www.jsdocs.io/package/aurelia-dependency-injection"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>