AliSoftware/Dip

Удержание аргумента при резольве объектов

NSSimpleApps opened this issue · 4 comments

class A {
    deinit {
        print("DEINIT A") // НЕ БУДЕТ ВЫЗВАН ДЛЯ swift4.2
    }
}
class B {
    weak var a: A?
    init(a: A) {
        self.a = a
    }
    deinit {
        print("DEINIT B")
    }
}
import Dip // 7.0
let container = DependencyContainer()    
let tag = "my_tag"
container.register(.unique, tag: tag,
factory: { arg in
     B(a: arg)
})
do {
     let a0 = A()
     let b0: B = try container.resolve(tag: tag, arguments: a0)
     print(a0, b0)
} catch {
     print(error)
}

При создании такой фабрики объектов аргумент a0 удерживается и не высвобождается при компиляции на Xcode10 swift4.2
Такой же код на Xcode9.4.1 swift4.1 не вызывает удержания объекта a0.

lol i dont think that anyone from here knows Russian language

@NSSimpleApps thanks for bringing this up. This turns out to be a swift bug, that should have been fixed https://bugs.swift.org/browse/SR-8878
Unfortunately I don't think there is currently a workaround for that as Dip automatically insects registered types using Mirror type to perform auto injection. Unless we consider #212 .

@NSSimpleApps you can now configure container to not attempt to auto inject properties if you don't use this feature. Unfortunately the issue will still be present if you use auto injection.

The fix is now released with 7.0.1. version