DIComponentBuilder

public final class DIComponentBuilder<Impl>

Component Builder. To create a used function register(_:) in class ContainerBuilder. The class allows you to configure all the necessary properties for the component.

  • Function allows you to specify a type by which the component will be available. Using:

    container.register(YourClass.self)
      .as(YourProtocol.self)
    

    Declaration

    Swift

    public func `as`<Parent>(_ type: Parent.Type) -> Self

    Parameters

    type

    Type by which the component will be available.

    Return Value

    Self

  • Function allows you to specify a type with tag by which the component will be available. Using:

    container.register(YourClass.self)
      .as(YourProtocol.self, tag: YourTag.self)
    

    Declaration

    Swift

    public func `as`<Parent, Tag>(_ type: Parent.Type, tag: Tag.Type) -> Self

    Parameters

    type

    Type by which the component will be available paired with tag.

    tag

    Tag by which the component will be available paired with type.

    Return Value

    Self

  • Function allows you to specify a type with name by which the component will be available. But! you can get an object by name in only two ways: use container method resolve(name:) or use injection(name:). Inside initialization method, you cann’t specify name for get an object. Use tags if necessary. Using:

    container.register(YourClass.self)
      .as(YourProtocol.self, name: "YourKey")
    

    Declaration

    Swift

    public func `as`<Parent>(_ type: Parent.Type, name: String) -> Self

    Parameters

    type

    Type by which the component will be available paired with name.

    name

    Name by which the component will be available paired with type.

    Return Value

    Self

  • Function allows you to specify a type with tag by which the component will be available. Using:

    container.register(YourClass.self)
      .as(check: YourProtocol.self){$0}
    

    WHERE YourClass implements YourProtocol

    Declaration

    Swift

    public func `as`<Parent>(check type: Parent.Type, _ validator: (Impl)->Parent) -> Self

    Parameters

    type

    Type by which the component will be available paired with tag.

    validator

    Validate type function. Always use {$0} for type validation.

    Return Value

    Self

  • Function allows you to specify a type with tag by which the component will be available. Using:

    container.register(YourClass.self)
      .as(check: YourProtocol.self, tag: YourTag.self){$0}
    

    WHERE YourClass implements YourProtocol

    Declaration

    Swift

    public func `as`<Parent, Tag>(check type: Parent.Type, tag: Tag.Type, _ validator: (Impl)->Parent) -> Self

    Parameters

    type

    Type by which the component will be available paired with tag.

    tag

    Tag by which the component will be available paired with type.

    validator

    Validate type function. Always use {$0} for type validation.

    Return Value

    Self

  • Function allows you to specify a type with name by which the component will be available. But! you can get an object by name in only two ways: use container method resolve(name:) or use injection(name:). Inside initialization method, you cann’t specify name for get an object. Use tags if necessary. Using:

    container.register(YourClass.self)
      .as(YourProtocol.self, name: "YourKey")
    

    WHERE YourClass implements YourProtocol

    Declaration

    Swift

    public func `as`<Parent>(check type: Parent.Type, name: String, _ validator: (Impl)->Parent) -> Self

    Parameters

    type

    Type by which the component will be available paired with name.

    name

    Name by which the component will be available paired with type.

    validator

    Validate type function. Always use {$0} for type validation.

    Return Value

    Self

  • Function for appending an injection method. In addition, container has a set of functions with a different number of parameters. Using:

    container.register(YourClass.self)
      .injection{ $0.yourClassProperty = YourValue }
    

    Also see: injection<Property>(cycle:_:)

    Declaration

    Swift

    public func injection(_ method: @escaping (Impl) -> ()) -> Self

    Parameters

    method

    Injection method. First input argument is the always created object.

    Return Value

    Self

  • Function for appending an injection method.

    Using:

    container.register(YourClass.self)
      .injection{ $0.yourClassProperty = $1 }
    

    OR

    container.register(YourClass.self)
      .injection{ yourClass, property in yourClass.property = property }
    

    OR if the injection participates in a cycle

    container.register(YourClass.self)
      .injection(cycle: true) { $0.yourClassProperty = $1 }
    

    Declaration

    Swift

    public func injection<Property>(cycle: Bool = false, _ method: @escaping (Impl,Property) -> ()) -> Self

    Parameters

    cycle

    true if the injection participates in a cycle. default false.

    method

    Injection method. First input argument is the always created object.

    Return Value

    Self

  • Function for appending an injection method. But for get an object used a specified name.

    Using:

    container.register(YourClass.self)
      .injection(name: "key") { $0.yourClassProperty = $1 }
    

    OR

    container.register(YourClass.self)
      .injection(name: "key") { yourClass, property in yourClass.property = property }
    

    OR if the injection participates in a cycle

    container.register(YourClass.self)
      .injection(name: "key", cycle: true) { $0.yourClassProperty = $1 }
    

    Declaration

    Swift

    public func injection<Property>(name: String, cycle: Bool = false, _ method: @escaping (Impl,Property) -> ()) -> Self

    Parameters

    name

    The specified name, for get an object.

    cycle

    true if the injection participates in a cycle. default false.

    method

    Injection method. First input argument is the always created object.

    Return Value

    Self

  • Function for appending an injection method which is always executed at end of a object creation. Using:

    container.register(YourClass.self)
      . ...
      .postInit{ $0.postInitActions() }
    

    Declaration

    Swift

    public func postInit(_ method: @escaping (Impl) -> ()) -> Self

    Parameters

    method

    Injection method. First input argument is the created object.

    Return Value

    Self

  • Function to set lifetime of an object. The lifetime of an object determines when it is created and destroyed. Using:

    container.register(YourClass.self)
      .lifetime(.prototype)
    

    Declaration

    Swift

    public func lifetime(_ lifetime: DILifeTime) -> Self

    Parameters

    lifetime

    LifeTime. for more information seeing enum DILifeTime.

    Return Value

    Self

  • Function declaring that this component will use the default. It’s necessary to resolve uncertainties if several components are available on one type. Component declared as default will be given in the case if there were clarifications that you need. But the components belonging to the framework have higher priority than the default components from other frameworks. Using:

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

    Declaration

    Swift

    public func `default`() -> Self

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1 in yourClass.yourMethod(p0, p1) }
    

    Declaration

    Swift

    public func injection<P0,P1>(_ m: @escaping (Impl,P0,P1) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2 in yourClass.yourMethod(p0, p1, p2) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2>(_ m: @escaping (Impl,P0,P1,P2) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3 in yourClass.yourMethod(p0, p1, p2, p3) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3>(_ m: @escaping (Impl,P0,P1,P2,P3) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3, p4 in yourClass.yourMethod(p0, p1, p2, p3, p4) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3,P4>(_ m: @escaping (Impl,P0,P1,P2,P3,P4) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3, p4, p5 in yourClass.yourMethod(p0, p1, p2, p3, p4, p5) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3,P4,P5>(_ m: @escaping (Impl,P0,P1,P2,P3,P4,P5) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3, p4, p5, p6 in yourClass.yourMethod(p0, p1, p2, p3, p4, p5, p6) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3,P4,P5,P6>(_ m: @escaping (Impl,P0,P1,P2,P3,P4,P5,P6) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3, p4, p5, p6, p7 in yourClass.yourMethod(p0, p1, p2, p3, p4, p5, p6, p7) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3,P4,P5,P6,P7>(_ m: @escaping (Impl,P0,P1,P2,P3,P4,P5,P6,P7) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self

  • Function for appending an injection method

    Using:

    container.register(YourClass.self)
      .injection{ yourClass, p0, p1, p2, p3, p4, p5, p6, p7, p8 in yourClass.yourMethod(p0, p1, p2, p3, p4, p5, p6, p7, p8) }
    

    Declaration

    Swift

    public func injection<P0,P1,P2,P3,P4,P5,P6,P7,P8>(_ m: @escaping (Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8) -> ()) -> Self

    Parameters

    m

    Injection method. First input argument is the always created object

    Return Value

    Self