DIContainer

public final class DIContainer

A container holding all registered components, allows you to register new components, parts, frameworks and allows you to receive objects by type.

  • Declaration

    Swift

    @discardableResult
    public func register1<Impl,P0>(file: String = #file, line: Int = #line, _ c: @escaping (P0) -> Impl) -> DIComponentBuilder<Impl>
  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10,p11:$11) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10,p11:$11,p12:$12) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10,p11:$11,p12:$12,p13:$13) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10,p11:$11,p12:$12,p13:$13,p14:$14) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. Using:

    container.register{ YourClass(p0:$0,p1:$1,p2:$2,p3:$3,p4:$4,p5:$5,p6:$6,p7:$7,p8:$8,p9:$9,p10:$10,p11:$11,p12:$12,p13:$13,p14:$14,p15:$15) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15) -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    c

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Registering a new component without initial. Using:

    container.register(YourClass.self)
      . ...
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl>(_ type: Impl.Type, file: String = #file, line: Int = #line) -> DIComponentBuilder<Impl>

    Parameters

    type

    A type of new component.

    Return Value

    component builder, to configure the component.

  • Declaring a new component with initial. In addition, container has a set of functions with a different number of parameters. Using:

    container.register(YourClass.init)
    

    OR

    container.register{ YourClass(p1: $0, p2: $1 as SpecificType, p3: $2) }
    

    Declaration

    Swift

    @discardableResult
    public func register<Impl>(file: String = #file, line: Int = #line, _ c: @escaping () -> Impl) -> DIComponentBuilder<Impl>

    Parameters

    initial

    initial method. Must return type declared at registration.

    Return Value

    component builder, to configure the component.

  • Resolve object by type. Can crash application, if can’t found the type. But if the type is optional, then the application will not crash, but it returns nil.

    Declaration

    Swift

    public func resolve<T>(from bundle: Bundle? = nil) -> T

    Parameters

    bundle

    Bundle from which to resolve a object

    Return Value

    Object for the specified type, or nil (see description).

  • Resolve object by type with tag. Can crash application, if can’t found the type with tag. But if the type is optional, then the application will not crash, but it returns nil.

    Declaration

    Swift

    public func resolve<T, Tag>(tag: Tag.Type, from bundle: Bundle? = nil) -> T

    Parameters

    tag

    Resolve tag.

    bundle

    Bundle from which to resolve a object

    Return Value

    Object for the specified type with tag, or nil (see description).

  • Resolve object by type with name. Can crash application, if can’t found the type with name. But if the type is optional, then the application will not crash, but it returns nil.

    Declaration

    Swift

    public func resolve<T>(name: String, from bundle: Bundle? = nil) -> T

    Parameters

    name

    Resolve name.

    bundle

    Bundle from which to resolve a object

    Return Value

    Object for the specified type with name, or nil (see description).

  • Resolve many objects by type.

    Declaration

    Swift

    public func resolveMany<T>() -> [T]

    Return Value

    Objects for the specified type.

  • Injected all dependencies into object. If the object type couldn’t be found, then in logs there will be a warning, and nothing will happen.

    Declaration

    Swift

    public func inject<T>(into object: T, from bundle: Bundle? = nil)

    Parameters

    object

    object in which injections will be introduced.

    bundle

    Bundle from which to injection into object

  • Initialize registered object with lifetime .single

    Declaration

    Swift

    public func initializeSingletonObjects()
  • Remove all cached object in container with lifetime perContainer(_)

    Declaration

    Swift

    public func clean()
  • Validate the graph by checking various conditions. For faster performance, set false.

    Declaration

    Swift

    @discardableResult
    public func validate(checkGraphCycles isCheckGraphCycles: Bool = true) -> Bool

    Parameters

    checkGraphCycles

    check cycles in the graph of heavy operation. So it can be disabled

    Return Value

    true if validation success.

  • Registers a framework in the container. Registration means inclusion of all components indicated within.

    Declaration

    Swift

    @discardableResult
    public func append(framework: DIFramework.Type) -> DIContainer

    Parameters

    framework

    the framework type

    Return Value

    self

  • Allows you to specify dependencies between frameworks. The method should be used only within the implementation of the load(container:) inside framework.

    Declaration

    Swift

    public func `import`(_ framework: DIFramework.Type)

    Parameters

    framework

    A framework that is imported into the current one. Import means communication designation, and not inclusion of all components.

  • Registers a part in the container. Registration means inclusion of all components indicated within.

    Declaration

    Swift

    @discardableResult
    public func append(part: DIPart.Type) -> DIContainer

    Parameters

    path

    the part type

    Return Value

    self

  • Registers a new storyboard. The storyboard can be created both from the code or use storyboard reference from otherwise a storyboard.

    Declaration

    Swift

    @discardableResult
    public func registerStoryboard(name: String, bundle storyboardBundleOrNil: Bundle? = nil, file: String = #file, line: Int = #line) -> DIComponentBuilder<UIStoryboard>

    Parameters

    name

    The name of the storyboard resource file without the filename extension.

    storyboardBundleOrNil

    The bundle containing the storyboard file and its resources. Specify nil to use the main bundle.

    Return Value

    component builder, to configure the component

  • Registers a new storyboard. The storyboard can be created both from the code or use storyboard reference from otherwise a storyboard.