diff --git a/Sources/Container.swift b/Sources/Container.swift index 12c35313..165c291a 100644 --- a/Sources/Container.swift +++ b/Sources/Container.swift @@ -217,7 +217,11 @@ extension Container: _Resolver { ) if let entry = getEntry(for: key) { - let factory = { [weak self] in self?.resolve(entry: entry, invoker: invoker) as Any? } + let factory = { [weak self] in + self?.lock.sync { // provide thread-safety + self?.resolve(entry: entry, invoker: invoker) as Any? + } + } return wrapper.init(inContainer: self, withInstanceFactory: factory) as? Wrapper } else { return wrapper.init(inContainer: self, withInstanceFactory: nil) as? Wrapper