-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically resolve differently for same protocl #345
Comments
Indeed this functionality is currently not quite supported by SwinjectStoryboard - I have answered more in depth in the SO issue. |
First of all thanks for the quick response. Currently when calling What if you would specify in the storyboard the available |
Thanks for the idea 👍 If we wanted to add the However, I'm not quite sure whether this is the right path to take: Initial idea behind the SwinjectStoryboard was to allow users relying on "hidden" instantiation of view controllers from storyboard (e.g. segues, child containers, ..) to inject dependencies. Once you need to use names in instantiation you cannot rely on these mechanisms anyway, so you might as well instantiate the view controllers manually: container.register(MyViewController.self, name: "name") {
let vc = SwinjectStoryboard.create(name: "MyStoryboard", bundle: nil).instantiateViewController(withIdentifier: "identifier")
vc.viewModel = $0.resolve(MyViewModel.self)!
return viewModel
}
let vc = SwinjectStoryboard.defaultContainer.resolve(MyViewController.self, name: "name") My fear is that once we start extending BTW: this argument works for adding resolution arguments (SwinjectStoryboard #62), which is taking the framework in the same direction. |
Well, according to your answer and a brief look on the implementation in Will adding a default value Because as I see it - from the moment you've instantiated the view controller from the storyboard, all you do is injecting the dependancy and return the injected viewController.
could cause any issues and will move the library to the direction you mentioned is wrong? |
This issue was moved to Swinject/SwinjectStoryboard#96 |
I'm trying to dynamically resolve a protocol
ViewModeling
that 2 different view models are conforming to..I am able to do it on the service level (one protocol that 2 services are conforming to, and 2 different viewModel that each consume a different service can resolve the required one using a specific
name
)I'm struggling with doing this on the viewController level, trying to inject the same view controller a specific viewModel (both conforms as mentioned to the same protocol).
I believe the issue is with
SwinjectStoryboard
that doesn't let me instantiate a view controller using its storyboard id (like I would normally do), and in addition define few different names that will be resolved on runtime.Am I missing something?
Just realised it might be more appropriate as a stackoverflaw post, so here is a link to the post:
https://stackoverflow.com/questions/49732300/how-to-inject-the-right-viewmodel-to-a-single-viewcontroller
The text was updated successfully, but these errors were encountered: