AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
978 stars 75 forks source link

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

Closed NSSimpleApps closed 5 years ago

NSSimpleApps commented 5 years ago
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.

aka-toxa commented 5 years ago

lol i dont think that anyone from here knows Russian language

ilyapuchka commented 5 years ago

@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 .

ilyapuchka commented 5 years ago

@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.

ilyapuchka commented 5 years ago

The fix is now released with 7.0.1. version