1

I am using Prism Wpf 8.1.97, and DryIoc container.

In my scenario i have to navigate between two views, so I implemented the INavigationAware Interface provided by Prism Framework in my viewModels.

I call the IRegionManager RequestNavigate method to perform the navigation from the VMA to VMB.

Unfortunately, I forgot to register a IService dependency that is needed in the VMB Ctor, so when I perform the navigation process I get the exception in the navigation callback.

The IService interface

    public interface IService
    {

    }

ViewModel A:

public class ViewAViewModel : BindableBase, INavigationAware
    {
        private readonly IRegionManager regionManager;

        public ViewAViewModel(IRegionManager regionManager)
        {
            this.regionManager = regionManager;
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            regionManager.TryRequestNavigate("ContentRegion", "ViewB", new NavigationParameters());
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

       public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

}

ViewModelB:

 public class ViewBViewModel : BindableBase, INavigationAware
        {
            public ViewBViewModel(IService service)
            {
    
            }
    
            public bool IsNavigationTarget(NavigationContext navigationContext)
            {
                return true;
            }
    
            public void OnNavigatedFrom(NavigationContext navigationContext)
            {
              
            }
    
        public void OnNavigatedTo(NavigationContext navigationContext)
            {
               
            }
        }

I created an extension method to keep it simple..

public static class IRegionManager_Extensions
{
    public static void TryRequestNavigate(this IRegionManager regionManager, string regionName, string target, NavigationParameters navigationParameters)
    {
        regionManager.RequestNavigate(regionName, target, NavigationResult =>
        {
            if (NavigationResult.Result == false)
            {
                MessageBox.Show(NavigationResult.Error.InnerException.Message, "Navigation Exception", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }, navigationParameters);
    }
}

Unfortunately what I get from the InnerException.Message is

ContainerException: code: Error.UnableToResolveFromRegisteredServices; message: Unable to resolve Resolution root Module1.ViewModels.ViewBViewModel from container without scope with Rules with {TrackingDisposableTransients, UseDynamicRegistrationsAsFallbackOnly, FuncAndLazyWithoutRegistration, SelectLastRegisteredFactory} and without {ThrowOnRegisteringDisposableTransient, UseFastExpressionCompilerIfPlatformSupported} with FactorySelector=SelectLastRegisteredFactory with Made={FactoryMethod=ConstructorWithResolvableArguments} with normal and dynamic registrations: (DefaultDynamicKey(0), {FactoryID=178, ImplType=Module1.ViewModels.ViewBViewModel, Reuse=TransientReuse, HasCondition})

without no reference to "IService"

I need to show that the navigation failed because IService implementation is not found in the container.

Is there a way to get the missing service Interface name from the exception?

Service name in the exception is null

Thanks.

Haukinger
  • 10,420
  • 2
  • 15
  • 28

0 Answers0