Closed alynmuntean closed 7 years ago
Is this an issue or is the lib being misused somehow?
I think you need to pass childContainer
to a initializer of SwinjectStoryboard.
@yoichitgy could you be more specific, with an example? It would help.
From the swiftInject docs, what @alynmuntean posted should work - https://github.com/Swinject/Swinject/blob/master/Documentation/ContainerHierarchy.md .
I think unit test code passing a container to SwinjectStoryboard can be an example.
Only defaultContainer
is automatically tied to SwinjectStoryboard. The other containers should be passed to SwinjectStoryboard manually.
So the idea is to create a new SwinjectStoryboard, which basically means a new Storyboard object, each time we want to call 'registerForStoryboard' on a childContainer?
I think it's each time you call a set of registerForStoryboard
methods on a container if you don't use defaultContainer
.
I'm sorry that I couldn't take more time to see your comments and code. Currently Swinject project has too many things to do.
Would you let me know if the issue is resolved?
You're trying to create a child container inside another container. This won't work as a parent doesn't resolve it's child(s) (docs: container hierarchy). By explicitly instantiating your storyboard you can pass your parent to your child. Which will then use your child instead of defaultContainer. If you want to, you can still use the SwinjectStoryboard extension for injection in your parent container. Injection in your child container will however have to be done somewhere else.
I had a similar issue for which I created a root configuration class which does root setup (plist reader, etc) and an app configuration class which resolves services, viewmodels, ..
let fooConfig = FooConfig()
let fooChildConfig = FooChildConfig(fooConfig.container)
let storyboard = SwinjectStoryboard.create(name: "Main", bundle: nil, container: fooChildConfig.container)
window.rootViewController = storyboard.instantiateInitialViewController()
let fooConfig = FooConfig(Swinjectstoryboard.defaultContainer)
let storyboard = SwinjectStoryboard.create(name: "Main", bundle: nil, container: fooConfig.container)
window.rootViewController = storyboard.instantiateInitialViewController()
Thanks @MathiasRoelants for writing the details about SwinjectStoryboard with a custom container, and sharing your experience with the examples.
@alynmuntean, did your question get clear?
@yoichitgy Yes, sorry that I forgot to answer. @MathiasRoelants Thank you for the example!
Hello, so I have the following view controller class, which is actually my initial view controller in storyboard:
On the "SwinjectStoryboard" extension, I do the following:
Resolver closures are never called, could you please help me understand why?
Note: When I register directly on "defaultContainer" (not on a child of it), it works ok.
Thank you in advance, Alin