NerdzInject

public final class NerdzInject

A class that registers and resolve all the dependencies

Singleton

  • SIngleton instance of a class

    Declaration

    Swift

    public static let shared: NerdzInject

Regiastering(Object)

  • Register an object based on instance type

    Declaration

    Swift

    public func registerObject<T>(_ object: T)

    Parameters

    object

    Registered instance that needs to be resolved later

  • Register an object for another type Might be useful when you want to register child object to be resolved for all parent requests

    Declaration

    Swift

    public func registerObject<T, V>(_ object: T, for type: V.Type)

    Parameters

    object

    Registered instance that needs to be resolved later

    type

    A type to what this instance needs to be resolved

  • Register an object that might be

    Declaration

    Swift

    public func registerObject<T>(_ object: T, for identifier: String)

    Parameters

    object

    Registered instance that needs to be resolved later

    identifier

    Unique dentifier that needs to be used for resolving instance in future

Registering(Closure)

  • Lazy register of an instance based on instance type The closure will be called on a moment when resolving is requested for instance type

    Declaration

    Swift

    public func register<T>(singleton: Bool = false, closure: @escaping () -> T)

    Parameters

    singleton

    If is enabled - instance that will be created after initial resolving, will be cached and used in future instead of creating a new one

    closure

    Closure that needs to create a new instance of a type

  • Lazy register of an instance based on provided type The closure will be called on a moment when resolving is requested for instance type

    Declaration

    Swift

    public func register<T, V>(singleton: Bool = false, for type: V.Type, closure: @escaping () -> T)

    Parameters

    singleton

    If is enabled - instance that will be created after initial resolving, will be cached and used in future instead of creating a new one

    type

    A type to what this instance needs to be resolved

    closure

    Closure that needs to create a new instance of a type

  • Lazy register of an instance based on provided identifier The closure will be called on a moment when resolving is requested for instance type

    Declaration

    Swift

    public func register<T>(singleton: Bool = false, for identifier: String, closure: @escaping () -> T)

    Parameters

    singleton

    If is enabled - instance that will be created after initial resolving, will be cached and used in future instead of creating a new one

    identifier

    A unique identifier that needs to be used for resolving an instance

    closure

    Closure that needs to create a new instance of a type

Resolving

  • Resoving an instance based on type

    Declaration

    Swift

    public func resolve<T>() -> T?

    Return Value

    Resolved instance if such exist

  • Resolving an instance based on provided type Return type might differ, for example if you know for sure that under registration type is a child instance

    Declaration

    Swift

    public func resolve<T, V>(by type: V.Type) -> T?

    Parameters

    type

    A type based on what library needs to resolve an instance

    Return Value

    Resolved instance if such exist

  • Resolving an instance based on provided identifier

    Declaration

    Swift

    public func resolve<T>(by identifier: String) -> T?

    Parameters

    identifier

    An identifier that was used during instance registration

    Return Value

    Resolved instance if such exist

Force Resolving

  • Force-resoving an instance based on type

    Declaration

    Swift

    public func forceResolve<T>() -> T

    Return Value

    Resolved instance or crash

  • Resolving an instance based on provided type Return type might differ, for example if you know for sure that under registration type is a child instance

    Declaration

    Swift

    public func forceResolve<T, V>(by type: V.Type) -> T

    Parameters

    type

    A type based on what library needs to resolve an instance

    Return Value

    Resolved instance or crash

  • Resolving an instance based on provided identifier

    Declaration

    Swift

    public func forceResolve<T>(by identifier: String) -> T

    Parameters

    identifier

    An identifier that was used during instance registration

    Return Value

    Resolved instance or crash

Removing

  • Removing registered instance if such exist

    Declaration

    Swift

    @discardableResult
    public func remove(by identifier: String) -> Bool

    Parameters

    identifier

    An identifier with what an instance was registered

    Return Value

    true if removing was successful

  • Removing registered instance if such exist

    Declaration

    Swift

    @discardableResult
    public func remove<T>(by type: T.Type) -> Bool

    Parameters

    type

    A type with what an instance was registered

    Return Value

    true if removing was successful