Helper class for resolving component dependencies.

Implements: IReferenceable, IReconfigurable


The DependencyResolver is a helper class that allows you to resolve component dependencies. It is configured to resolve named dependencies by a specific locator.

Important points:

  • During deployment the dependency locator can be changed. This mechanism can be used to clarify a specific dependency among several alternatives. Typically components are configured to retrieve the first dependency that matches a logical group, type and version. However, if the container contains more than one instance and the resolution has to be specific about those instances, they can be given a unique name and the dependency resolvers can be reconfigured to retrieve dependencies according to their name.

Configuration parameters

  • dependencies:
    • [dependency name 1]: Dependency 1 locator (descriptor)
    • [dependency name N]: Dependency N locator (descriptor)


References must match configured dependencies.


Creates a new instance of the dependency resolver.

public constructor(config?: ConfigParams, references?: IReferences)

  • config: ConfigParams - (optional) default configuration where key the is dependency name and value is the locator (descriptor)
  • references: IReferences - (optional) default component references

Instance methods


Configures the component with specified parameters.

public configure(config: ConfigParams): void


Finds all matching dependencies by their name.

public find<T>(name: string, required: boolean): T[]

  • name: string - dependency name to locate.
  • required: boolean - true to raise an exception when no dependencies are found.
  • returns: T[] - list of found dependencies


Gets one optional dependency by its name.

public getOneOptional<T>(name: string): T

  • name: string - dependency name to locate.
  • returns: T - dependency reference or null if the dependency was not found.


Gets one required dependency by its name. At least one dependency must present. If the dependency was found it throws a ReferenceException.

public getOneRequired<T>(name: string): T

  • name: string - dependency name to locate.
  • returns: T - dependency reference


Gets all optional dependencies by their name.

public getOptional<T>(name: string): T[]

  • name: string - dependency name to locate.
  • returns: T[] - list with found dependencies or empty list of no dependencies was found.


Gets all required dependencies by their name. At least one dependency must be present. If no dependency was found, it throws a ReferenceException

public getRequired<T>(name: string): T[]

  • name: string - dependency name to locate.
  • returns: T[] - list with found dependencies.


Adds a new dependency into this resolver.

public put(name: string, locator: any): void

  • name: string - dependency’s name.
  • locator: any - locator to find the dependency by.


Sets the component references. References must match configured dependencies.

public setReferences(references: IReferences): void

Static methods


Creates a new DependencyResolver from a list of key-value pairs called tuples where key is a dependency name and value the depedency locator (descriptor).

public static fromTuples(…tuples: any[]): DependencyResolver

  • tuples: any[] - list of values where odd elements are dependency names and the following even elements are dependency locators (descriptor).
  • returns: DependencyResolver - newly created DependencyResolver.


class MyComponent: IConfigurable, IReferenceable {
    private _dependencyResolver: DependencyResolver = new DependencyResolver();
    private _persistence: IMyPersistence;
    public constructor() {
        this._dependencyResolver.put("persistence", new Descriptor("mygroup", "persistence", "*", "*", "1.0"));
    public configure(config: ConfigParams): void {
    public setReferences(references: IReferences): void {
        this._persistence = this._dependencyResolver.getOneRequired<IMyPersistence>("persistence");
// Create mycomponent and set specific dependency out of many
let component = new MyComponent();
    "dependencies.persistence", "mygroup:persistence:*:persistence2:1.0" 
// Override default persistence dependency
    new Descriptor("mygroup","persistence","*","persistence1","1.0"), new MyPersistence(),
    new Descriptor("mygroup","persistence","*","persistence2","1.0"), new MyPersistence()  
// This dependency shall be set

See also