Resolver

public final class Resolver

Resolver is a Dependency Injection registry that registers Services for later resolution and injection into newly constructed instances.

  • Default registry used by the static Registration functions.

    Declaration

    Swift

    public static let main: Resolver = Resolver()
  • Default registry used by the static Resolution functions and by the Resolving protocol.

    Declaration

    Swift

    public static var root: Resolver = main
  • Default scope applied when registering new objects.

    Declaration

    Swift

    public static var defaultScope = Resolver.graph
  • Declaration

    Swift

    public init(parent: Resolver? = nil)
  • Called by the Resolution functions to perform one-time initialization of the Resolver registries.

    Declaration

    Swift

    public final func registerServices()
  • Static shortcut function used to register a specifc Service type and its instantiating factory method.

    Declaration

    Swift

    public static func register<Service>(_ type: Service.Type = Service.self, name: String? = nil,
                                         factory: @escaping ResolverFactory<Service>) -> ResolverOptions<Service>

    Parameters

    type

    Type of Service being registered. Optional, may be inferred by factory result type.

    name

    Named variant of Service being registered.

    factory

    Closure that constructs and returns instances of the Service.

    Return Value

    ResolverOptions instance that allows further customization of registered Service.

  • Static shortcut function used to register a specifc Service type and its instantiating factory method.

    Declaration

    Swift

    public static func register<Service>(_ type: Service.Type = Service.self, name: String? = nil,
                                         factory: @escaping ResolverFactoryArguments<Service>) -> ResolverOptions<Service>

    Parameters

    type

    Type of Service being registered. Optional, may be inferred by factory result type.

    name

    Named variant of Service being registered.

    factory

    Closure that accepts arguments and constructs and returns instances of the Service.

    Return Value

    ResolverOptions instance that allows further customization of registered Service.

  • Registers a specifc Service type and its instantiating factory method.

    Declaration

    Swift

    public final func register<Service>(_ type: Service.Type = Service.self, name: String? = nil,
                                        factory: @escaping ResolverFactory<Service>) -> ResolverOptions<Service>

    Parameters

    type

    Type of Service being registered. Optional, may be inferred by factory result type.

    name

    Named variant of Service being registered.

    factory

    Closure that constructs and returns instances of the Service.

    Return Value

    ResolverOptions instance that allows further customization of registered Service.

  • Registers a specifc Service type and its instantiating factory method.

    Declaration

    Swift

    public final func register<Service>(_ type: Service.Type = Service.self, name: String? = nil,
                                        factory: @escaping ResolverFactoryArguments<Service>) -> ResolverOptions<Service>

    Parameters

    type

    Type of Service being registered. Optional, may be inferred by factory result type.

    name

    Named variant of Service being registered.

    factory

    Closure that accepts arguments and constructs and returns instances of the Service.

    Return Value

    ResolverOptions instance that allows further customization of registered Service.

  • Resolves and returns an instance of the given Service type from the current registry or from its parent registries.

    Declaration

    Swift

    public final func resolve<Service>(_ type: Service.Type = Service.self, name: String? = nil, args: Any? = nil) -> Service

    Parameters

    type

    Type of Service being resolved. Optional, may be inferred by assignment result type.

    name

    Named variant of Service being resolved.

    args

    Optional arguments that may be passed to registration factory.

    Return Value

    Instance of specified Service.

  • Resolves and returns an optional instance of the given Service type from the current registry or from its parent registries.

    Declaration

    Swift

    public final func optional<Service>(_ type: Service.Type = Service.self, name: String? = nil, args: Any? = nil) -> Service?

    Parameters

    type

    Type of Service being resolved. Optional, may be inferred by assignment result type.

    name

    Named variant of Service being resolved.

    args

    Optional arguments that may be passed to registration factory.

    Return Value

    Instance of specified Service.