Documentation
    Preparing search index...

    Class ContainerResolver<KnownBindings>

    Container resolver exposes the APIs to resolve bindings. You can think of resolver as an isolated container instance, with only the APIs to resolve bindings.

    const container = new Container()
    const resolver = container.createResolver()

    await resolver.make(BINDING_NAME)
    await resolver.make(CLASS_CONSTRUCTOR)

    Type Parameters

    • KnownBindings extends Record<any, any>
    Index

    Constructors

    Methods

    • Find if the resolver has a binding registered using the "bind", the "singleton", or the "bindValue" methods.

      Type Parameters

      • Binding extends string | number | symbol

      Parameters

      Returns boolean

      True if binding exists, false otherwise

    • Find if the resolver has a binding registered using the "bind", the "singleton", or the "bindValue" methods.

      Parameters

      Returns boolean

      True if binding exists, false otherwise

    • Find if the resolver has all the bindings registered using the "bind", the "singleton", or the "bindValue" methods.

      Type Parameters

      • Binding extends string | number | symbol

      Parameters

      Returns boolean

      True if all bindings exist, false otherwise

    • Find if the resolver has all the bindings registered using the "bind", the "singleton", or the "bindValue" methods.

      Parameters

      Returns boolean

      True if all bindings exist, false otherwise

    • Resolves binding in context of a parent. The method is same as the "make" method, but instead takes a parent class constructor.

      Type Parameters

      • Binding

      Parameters

      Returns Promise<Make<Binding>>

    • Resolves the binding or constructor a class instance as follows.

      • Resolve the binding from the values (if registered)
      • Resolve the binding from the bindings (if registered)
      • If binding is a class, then create a instance of it. The constructor dependencies are further resolved as well.
      • All other values are returned as it is.
      await resolver.make('route')
      await resolver.make(Database)

      Type Parameters

      • Binding extends string | number | symbol

      Parameters

      Returns Promise<
          Binding extends string
          | symbol
              ? KnownBindings[Binding<Binding>]
              : Make<Binding>,
      >

    • Resolves the binding or constructor a class instance as follows.

      • Resolve the binding from the values (if registered)
      • Resolve the binding from the bindings (if registered)
      • If binding is a class, then create a instance of it. The constructor dependencies are further resolved as well.
      • All other values are returned as it is.
      await resolver.make('route')
      await resolver.make(Database)

      Type Parameters

      • Binding

      Parameters

      Returns Promise<Make<Binding>>

    • Call a method on an object by injecting its dependencies. The method dependencies are resolved in the same manner as a class constructor dependencies.

      await resolver.call(await resolver.make(UsersController), 'index')
      

      Type Parameters

      • Value extends Record<any, any>
      • Method extends string | number | symbol

      Parameters

      Returns Promise<ReturnType<Value[Method]>>

    • Register a binding as a value

      container.bindValue(Route, new Route())
      

      Type Parameters

      • Binding extends string | number | symbol

      Parameters

      Returns void

      Binds the value to the resolver

    • Register a binding as a value

      container.bindValue(Route, new Route())
      

      Type Parameters

      • Binding extends AbstractConstructor<any>

      Parameters

      Returns void

      Binds the value to the resolver