Functions
The following functions are available globally.
-
Short syntax for resolve. Using:
let yourObj: YourClass = *container
Declaration
Swift
public prefix func * <T>(container: DIContainer) -> T
Parameters
container
A container.
Return Value
Created object.
-
Short syntax for get object by tag Using:
let object: YourType = by(tag: YourTag.self, on: *container)
also can using in injection or init:
.injection{ $0.property = by(tag: YourTag.self, on: $1) }
Declaration
Swift
public func by<Tag, T>(tag: Tag.Type, on obj: DIByTag<Tag, T>) -> T
Parameters
tag
a tag
obj
resolving object
Return Value
resolved object
-
Short syntax for get object by two tags Using:
let object: YourType = by(tags: YourTag.self, YourTag2.self, on: *container)
also can using in injection or init:
.injection{ $0.property = by(tags: YourTag.self, YourTag2.self, on: $1) }
Declaration
Parameters
tag
a tag
obj
resolving object
Return Value
resolved object
-
Short syntax for get object by three tags Using:
let object: YourType = by(tags: YourTag.self, YourTag2.self, YourTag3.self, on: *container)
also can using in injection or init:
.injection{ $0.property = by(tags: YourTag.self, YourTag2.self, YourTag3.self, on: $1) }
Declaration
Parameters
tag
a tag
obj
resolving object
Return Value
resolved object
-
Short syntax for get many objects Using:
let objects: [YourType] = many(*container)
also can using in injection or init:
.injection{ $0.property = many($1) }
Declaration
Swift
public func many<T>(_ obj: DIMany<T>) -> [T]
Parameters
obj
resolving objects
Return Value
resolved objects
-
Short syntax for get many objects in bundle Using:
let objects: [YourType] = manyInBundle(*container)
also can using in injection or init:
.injection{ $0.property = manyInBundle($1) }
Declaration
Swift
public func manyInBundle<T>(_ obj: DIManyInBundle<T>) -> [T]
Parameters
obj
resolving objects
Return Value
resolved objects
-
Short syntax for get object use arguments Simple using:
container.register{ YourClass(p1: $0, p2: arg($1)) } .injection{ $0.property = arg($1) } ... container.extension(for: YourClass.self).setArgs(15, "it's work!") let yourClass = *container // p1 - injected, p2 = 15, property = "it's work!"
Also your forward parameters at any depth Warning: not use with cycle injection
.injection(cycle: true...
- it’s not good Warning: Unsafe type - if you pass an object of wrong type, The library will fall. Exception: type of optionalDeclaration
Swift
public func arg<T>(_ obj: DIArg<T>) -> T
Parameters
name
The external name for the argument
obj
resolving object
Return Value
resolved object