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 var main: Resolver
-
Default registry used by the static Resolution functions and by the Resolving protocol.
Declaration
Swift
public static var root: Resolver
-
Default scope applied when registering new objects.
Declaration
Swift
public static var defaultScope: ResolverScope
-
Undocumented
Declaration
Swift
public init(parent: Resolver? = nil)
-
Call function to force one-time initialization of the Resolver registries. Usually not needed as functionality occurs automatically the first time a resolution function is called.
Declaration
Swift
public final func registerServices()
-
Call function to force one-time initialization of the Resolver registries. Usually not needed as functionality occurs automatically the first time a resolution function is called.
Declaration
Swift
public static var registerServices: (() -> Void)?
-
Called to effectively reset Resolver to its initial state, including recalling registerAllServices if it was provided. This will also reset the three known caches: application, cached, shared.
Declaration
Swift
public static func reset()
-
Static shortcut function used to register a specifc Service type and its instantiating factory method.
Declaration
Swift
@discardableResult public static func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = 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
@discardableResult public static func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = nil, factory: @escaping ResolverFactoryResolver<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 with multiple argument support.
Declaration
Swift
@discardableResult public static func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = nil, factory: @escaping ResolverFactoryArgumentsN<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
@discardableResult public final func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = 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
@discardableResult public final func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = nil, factory: @escaping ResolverFactoryResolver<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 with multiple argument support.
Declaration
Swift
@discardableResult public final func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = nil, factory: @escaping ResolverFactoryArgumentsN<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.
-
Static function calls the root registry to resolve a given Service type.
Declaration
Swift
public static func resolve<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = 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 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: Resolver.Name? = 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.
-
Static function calls the root registry to resolve an optional Service type.
Declaration
Swift
public static func optional<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = 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: Resolver.Name? = 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.
-
Undocumented
Declaration
Swift
public static let application: ResolverScopeCache
-
Undocumented
Declaration
Swift
public static let cached: ResolverScopeCache
-
Undocumented
Declaration
Swift
public static let graph: ResolverScopeGraph
-
Undocumented
Declaration
Swift
public static let shared: ResolverScopeShare
-
Undocumented
Declaration
Swift
public static let unique: ResolverScopeUnique