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.
-
Make entry point for library
Declaration
Swift
public init(parent: DIContainer? = nil)
Parameters
parent
parent container. first there is an attempt resolve from self, after from parent. For
many
resolve from both and recursive
-
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`(_ importFramework: 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
-
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.
-
Method for creating an object capable of customizing extensions
Declaration
Swift
public func extensions(for type: DIAType, name: String? = nil, framework: DIFramework.Type? = nil, file: String = #file, line: Int = #line) -> DIExtensions?
Parameters
type
object type for which extensions are specified. Сan be tagged
name
optional. Qualified name by which to retrieve a specific component
framework
optinal. Qualified framework to which component belongs
Return Value
object for customizing extensions
-
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. Using:
container.register{ YourClass(p0:$0) }
Declaration
Swift
@discardableResult public func register<Impl,P0>(file: String = #file, line: Int = #line, _ c: @escaping (P0) -> Impl) -> DIComponentBuilder<Impl>
Parameters
c
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 framework: DIFramework.Type? = nil) -> T
Parameters
framework
Framework 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 framework: DIFramework.Type? = nil) -> T
Parameters
tag
Resolve tag.
framework
Framework 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 framework: DIFramework.Type? = nil) -> T
Parameters
name
Resolve name.
framework
Framework 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 framework: DIFramework.Type? = nil)
Parameters
object
object in which injections will be introduced.
framework
Framework 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 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: Bundle? = nil, file: String = #file, line: Int = #line) -> DIComponentBuilder<UIStoryboard>
Parameters
name
The name of the storyboard resource file without the filename extension.
bundle
The bundle containing the storyboard file and its resources.
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.