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.
-
Undocumented
Declaration
Swift
public final class DIContainer
-
swift4 bug: https://bugs.swift.org/browse/SR-5112
Declaration
Swift
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
-
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,p16:$16) }
Declaration
Swift
public func register<Impl,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16>(file: String = #file, line: Int = #line, _ c: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16) -> Impl) -> DIComponentBuilder<Impl>
Parameters
c
initial method. Must return type declared at registration.
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.
Declaration
Swift
public func registerStoryboard(name: String, bundle storyboardBundleOrNil: Bundle?, 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.
Declaration
Swift
public final class DIContainer
-
Registering a new component without initial. Using:
container.register(YourClass.self) . ...
Declaration
Swift
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
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>() -> T
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) -> T
Parameters
tag
Resolve tag.
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) -> T
Parameters
name
Resolve name.
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)
Parameters
object
object in which injections will be introduced.
-
Undocumented
Declaration
Swift
public final class DIContainer
-
Validate the graph by checking various conditions. For faster performance, set false.
Declaration
Swift
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
public func append(framework: DIFramework.Type)
Parameters
framework
the framework type
-
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
public func append(part: DIPart.Type)
Parameters
path
the part type