question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty stack in injected INavigationService while configured with MS DI container

See original GitHub issue

Steps:

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremyBPcommented, Jun 30, 2020

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.

0reactions
dansiegelcommented, Aug 27, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection error: Unable to resolve service for ...
c# - Dependency Injection error: Unable to resolve service for type while attempting to activate, while class is registered - Stack Overflow.
Read more >
Dependency injection guidelines - .NET
This article provides general guidelines and best practices for implementing dependency injection in .NET applications.
Read more >
Setting up a basic MVVM architecture in .NET MAUI
I would like a NavigationService to be injected in my ViewModels, so that I can perform a navigation from a command that was...
Read more >
Understanding Dependency Injection in .NET Core
Disposition: the IoC Container manages the lifetime of the dependencies following specific criteria. You will see these features in action in a while....
Read more >
What does Dependency Injection mean by saying it can ...
yes, change the configuration and change the runtime behavior. basically Dependency injection to me means: writing java changed to writing XML.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found