Swinject: initCompleted not hit

Created on 4 May 2017  路  2Comments  路  Source: Swinject/Swinject

What could be a reason that initCompleted would not be hit even if the class itself has been initialized?

defaultContainer.register(Foo.self) { _ in Foo() }.initCompleted { resolver, foo in // this is not hit }.inObjectScope(.container)

initCompleted is never hit but I have:
let foo: Foo = Foo()

called in the initializer of a class and I have checked, that line is hit and the instance of Foo is created.

All the other registrations are working except this one.

I am using v2.0.0

question

All 2 comments

I'm not sure if I understood you correctly: is let foo: Foo = Foo() the code which you expect should call .initCompleted?
If that is so, you are creating an instance in the wrong way - you should not call the initializer directly, but rather through the Swinject container: let foo = container.resolve(Foo.self)

Thank you! That is exactly what I did wrong :)

Was this page helpful?
0 / 5 - 0 ratings