DependencyContainer.resolve

Resolve dependencies.

Dependencies can only resolved using this method if they are registered by concrete type or the only concrete type registered by super type.

Resolved dependencies are automatically autowired before being returned.

  1. RegistrationType resolve(ResolveOption resolveOptions)
    class DependencyContainer
    public
    RegistrationType
    resolve
    (
    RegistrationType
    )
    if (
    !is(RegistrationType == struct)
    )
  2. QualifierType resolve(ResolveOption resolveOptions)

Return Value

Type: RegistrationType

An instance is returned which is created according to the registration scope with which they are registered.

Throws

ResolveException when type is not registered.

Examples

Resolve dependencies registered by super type and concrete type:

class Cat : Animal { ... }
class Dog : Animal { ... }

container.register!(Animal, Cat);
container.register!Dog;

container.resolve!Animal;
container.resolve!Dog;

You cannot resolve a dependency when it is registered by multiple super types:

class Cat : Animal { ... }
class Dog : Animal { ... }

container.register!(Animal, Cat);
container.register!(Animal, Dog);

container.resolve!Animal; // Error: multiple candidates for type "Animal"
container.resolve!Dog; // Error: No type is registered by concrete type "Dog", only by super type "Animal"

You need to use the resolve method which allows you to specify a qualifier.

Meta