[英]Swinject factory closure called multiple times when object scope is container
I'm trying to register CoreDataStack as a single instance on a shared container with object scope .container
, but its factory closure called multiple times and when I debug memory graph in Xcode several instances of the object are created even when the returned object is not值類型!
Swinject 文檔:
如果工廠關閉返回值類型,則忽略 object scope,因為它的實例從不根據 Swift 規范共享。
這種奇怪行為的根本原因是什么?
使用名稱注冊服務可以解決問題並且不再創建實例
container.register(CoreDataStack.self, name: "CoreDataStack") {
DefaultCoreDataStack(modelName: "name")
}.inObjectScope(.container)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.