-2

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?

Ali Baqbani
  • 153
  • 1
  • 2
  • 13

1 Answers1

1

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)
Ali Baqbani
  • 153
  • 1
  • 2
  • 13