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

    Swift

    public func by<Tag1, Tag2, T>(tags: Tag1.Type, _ t: Tag2.Type, on obj: DIByTag<Tag1, DIByTag<Tag2, T>>) -> T

    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

    Swift

    public func by<Tag1, Tag2, Tag3, T>(tags: Tag1.Type, _ t2: Tag2.Type, _ t3: Tag3.Type, on obj: DIByTag<Tag1, DIByTag<Tag2, DIByTag<Tag3, T>>>) -> T

    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 framework Using:

    let objects: [YourType] = manyInFramework(*container)
    

    also can using in injection or init:

    .injection{ $0.property = manyInFramework($1) }
    

    Declaration

    Swift

    public func manyInFramework<T>(_ obj: DIManyInFramework<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 optional

    Declaration

    Swift

    public func arg<T>(_ obj: DIArg<T>) -> T

    Parameters

    name

    The external name for the argument

    obj

    resolving object

    Return Value

    resolved object