Swinject/SwinjectAutoregistration

Init methods can be called multiple times even with .container scope

vminc opened this issue · 1 comments

vminc commented

With the following registration, I would expect that the init method for A is called once because I marked A as .container (Singleton) scope, but it seems to be called multiple times. Is this the expected behavior or is there something that I'm missing?

container.autoregister(
      A.self,
      initializer: A.init)
      .inObjectScope(.container)
container.register(B.self) { r in r.resolve(A.self)! }
container.register(C.self) { r in r.resolve(A.self)! }

A.init is still called twice even if I mark B and C as container scope

container.autoregister(
      A.self,
      initializer: A.init)
      .inObjectScope(.container)
container.register(B.self) { r in r.resolve(A.self)! }      .inObjectScope(.container)
container.register(C.self) { r in r.resolve(A.self)! }      .inObjectScope(.container)

And multiple instances of A is actually created.

I'm on ver 2.0.1