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
typeType of Service being registered. Optional, may be inferred by factory result type.
nameNamed variant of Service being registered.
factoryClosure 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
typeType of Service being registered. Optional, may be inferred by factory result type.
nameNamed variant of Service being registered.
factoryClosure 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
typeType of Service being registered. Optional, may be inferred by factory result type.
nameNamed variant of Service being registered.
factoryClosure 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
typeType of Service being registered. Optional, may be inferred by factory result type.
nameNamed variant of Service being registered.
factoryClosure 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) -> ServiceParameters
typeType of Service being resolved. Optional, may be inferred by assignment result type.
nameNamed variant of Service being resolved.
argsOptional 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
typeType of Service being resolved. Optional, may be inferred by assignment result type.
nameNamed variant of Service being resolved.
argsOptional arguments that may be passed to registration factory.
Return Value
Instance of specified Service.
-
Declaration
Swift
public static let application = ResolverScopeApplication() -
Declaration
Swift
public static let cached = ResolverScopeCache() -
Declaration
Swift
public static let graph = ResolverScopeGraph() -
Declaration
Swift
public static let shared = ResolverScopeShare() -
Declaration
Swift
public static let unique = ResolverScopeUnique()
Resolver Class Reference