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 for appending an injection method
Using:
container.register(YourClass.self) .injection{ yourClass, p0, p1 in yourClass.yourMethod(p0, p1) }
Declaration
Swift
@discardableResult 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
@discardableResult 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
@discardableResult 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
@discardableResult 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
@discardableResult 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
@discardableResult 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
@discardableResult 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 allows you to specify a type by which the component will be available. Using:
container.register(YourClass.self) .as(YourProtocol.self)
Declaration
Swift
@discardableResult 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
@discardableResult 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 useinjection(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
@discardableResult 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
@discardableResult 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
@discardableResult 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 useinjection(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
@discardableResult 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
@discardableResult 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. Your Can use specified name for get an object.
Using:
container.register(YourClass.self) .injection { $0.yourClassProperty = $1 } container.register(YourClass.self) .injection(name: "key") { $0.yourClassProperty = $1 }
OR
container.register(YourClass.self) .injection { yourClass, property in yourClass.property = property } 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 } container.register(YourClass.self) .injection(cycle: true) { $0.yourClassProperty = $1 }
Declaration
Swift
@discardableResult public func injection<Property>(name: String? = nil, cycle: Bool = false, _ method: @escaping (Impl, Property) -> ()) -> Self
Parameters
name
The specified name, for get an object. or nil.
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. Your Can use specified name for get an object.
Using:
container.register(YourClass.self) .injection(\YourClass.yourClassProperty) { many($0) } container.register(YourClass.self) .injection(name: "key", \.yourClassProperty) { by(tag: YourTag.self, on: $0) }
OR if the injection participates in a cycle
container.register(YourClass.self) .injection(name: "key", cycle: true, \.yourClassProperty) { by(tag: YourTag.self, on: $0) } container.register(YourClass.self) .injection(cycle: true, \YourClass.yourClassProperty) { many($0) }
Declaration
Swift
@available(swift 4.0) @discardableResult public func injection<P, Property>(name: String? = nil, cycle: Bool = false, _ keyPath: ReferenceWritableKeyPath<Impl, P>, _ modificator: @escaping (Property) -> P) -> Self
Parameters
name
The specified name, for get an object. or nil.
cycle
true if the injection participates in a cycle. default false.
method
Injection method. First input argument is the always created object.
modificator
Need for support set many / tag on property.
Return Value
Self
-
Function for appending an injection method. Your Can use specified name for get an object.
Using:
container.register(YourClass.self) .injection(\.yourClassProperty) container.register(YourClass.self) .injection(name: "key", \YourClass.yourClassProperty)
OR if the injection participates in a cycle
container.register(YourClass.self) .injection(name: "key", cycle: true, \YourClass.yourClassProperty) container.register(YourClass.self) .injection(cycle: true, \.yourClassProperty)
Declaration
Swift
@available(swift 4.0) @discardableResult public func injection<Property>(name: String? = nil, cycle: Bool = false, _ keyPath: ReferenceWritableKeyPath<Impl, Property>) -> Self
Parameters
name
The specified name, for get an object. or nil.
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
@discardableResult 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
@discardableResult 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
@discardableResult public func `default`() -> Self
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 “test” 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. Has the greatest power “default” Using:
container.register(YourClass.self) .test()
Declaration
Swift
@discardableResult public func test() -> Self
Return Value
Self
-
Function allows injection inside UIViewController view and its subviews. Setted to false by default cause optimization purposes. If you want enable injection into ViewController views, UITableViewCells and UICollectionViewCells, set this property to true.
Declaration
Swift
@discardableResult public func autoInjectToSubviews() -> Self
Return Value
Self
-
Function allows injection inside UIView and its subviews. Setted to false by default cause optimization purposes. If you want enable injection into views, UITableViewCells and UICollectionViewCells, set this property to true.
Declaration
Swift
@discardableResult public func autoInjectToSubviews() -> Self
Return Value
Self