Empty stack in injected INavigationService while configured with MS DI container
See original GitHub issueSteps:
Based on the sample included in this repository:
- configure your sample with MS DI container
- create another page and vm like OtherPage/OtherPageViewModel
- add a button to the MainPage to navigate to OtherPage
- bind the button command to an ICommand on the MainPageViewModel side
- Use the injected INavigationService to setup navigation to OtherPage, with a NavigationPage
- Execute
In other other words, navigate from a page to another with a binded button command (no pb with xaml nav) and with a NavigationPage 😃
Expected behavior:
Injected INavigationService implementation instance into the MainPageViewModel constructor should get the MainPage as its Page property. The OtherPage should be pushed on screen with a nav bar and a back button. If we press back, it should return to the MainPage
Actual behavior
INavigationService’s Page property is allways null. The other page is pushed without a back button. If we press back it close the app.
No pb with DryIoc container. Other containers not tested.
Quick fix and probably dirty:
In PrismContainerExtension’s GetChildProvider method, we register the needed ViewModel dedicated’s INavigationService implementation instance but then, in ConcreteAwareServiceProvider’s GetConcreteImplementation we rebuild the service provider based on a non up to date service collection.
That’s why the ViewModel resolution can’t find the previously added navigation service.
My workaround was to add :
SetServiceCollection(services);
just before :
var rootSP = services.BuildServiceProvider();
into the PrismContainerExtension’s GetChildProvider method. But not sure of side effects…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top GitHub Comments
Oups you’re right. Originally, I fixed the pb by writing Services = services; at L334, and this actually fixes the pb for the reason we talked about. Then, I changed it to the cleaner provided method called SetServiceCollection(services); just before this PR, but without testing it, my bad 😦 Anyway, if you replace the SetServiceCollection by Services = services, it should work. Sorry about that.
I believe the issue should be resolved with the v8 branch. It will be available in the SponsorConnect feed, and will be on NuGet sometime next week. I’m closing this for now. If the problem persists in v8 please let me know