Reputation: 153
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 value-type!
Swinject documentation:
The object scope is ignored if the factory closure returns a value type because its instance is never shared per the Swift specification.
What is the root cause of this strange behavior?
Upvotes: -2
Views: 550
Reputation: 153
Registering a service with a name solve the issue and no more instances created
container.register(CoreDataStack.self, name: "CoreDataStack") {
DefaultCoreDataStack(modelName: "name")
}.inObjectScope(.container)
Upvotes: 1