It seems that when I resolve a type manually and request the INavigationService in it a different instance is injected than the one being used everywhere else.
To clearify my use-case here are excerpts from the relevant files. As you can see when resolving the type SampleProcess the INavigationService will be injected but the instance is different to the one that I got in ProcessService. (Which btw is the correct instance, that can be used for navigation. The one injected in SampleProcess cannot be used for navigating.)
Any ideas why this is happening and more importantely how I can get the correct instance of INavigationService be injected into SampleProcess. Yes, I could provide it for example by passing it in with a method, but that's not so pretty.
App.xaml.cs
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<ProcessService>();
containerRegistry.Register<Processes.SampleProcess>();
}
ProcessService.cs
public class ProcessService
{
private readonly IContainer container;
private readonly INavigationService navigationService;
public ProcessService(IContainer container, INavigationService navigationService)
{
this.container = container;
this.navigationService = navigationService;
}
public void ExecuteProcess(ProcessEnum processEnumValue)
{
Type processType = processEnumValue switch
{
ProcessEnum.SampleProcess => typeof(Processes.SampleProcess),
_ => throw new NotImplementedException()
};
var process = App.Current.Container.Resolve(processType) as IProcess;
bool test = process.CheckNavigationService(navigationService); // will return false
}
}
SampleProcess.cs
public class SampleProcess : IProcess
{
private readonly INavigationService navigationService;
public SampleProcess(INavigationService navigationService)
{
this.navigationService = navigationService;
}
public bool CheckNavigationService(INavigationService navigationService)
{
return this.navigationService == navigationService;
}
}