I am trying to create an error page service which, when called, will determine which type of exception has occurred and processes the code properly. If the exception is of type "redirect", it should send the user to a login page (for testing purposes, I'm just using the home "/" page).
I'm trying to use NavigationMangager.NavigateTo("/") but am running into a Null point exception whenever I reach that function call. I've been looking for a solution to this for a while now but everything I see is usage of NavigationManager in .razor files and I'm trying to complete this within a .cs service. Is this not possible currently or am I just doing something wrong? I've included all the relevant code from my file "ErrorProcessingService.cs" below, any help would be appreciated.
using ToDoList.Pages;
using Microsoft.AspNetCore.Components;
namespace ToDoList.ExceptionHandler
{
public class ErrorProcessingService
{
[Inject]
protected NavigationManager NavigationManager {get; set;}
public void processError(ErrorTypes.errorType et)
{
new ErrorTypes();
switch(et)
{
case ErrorTypes.errorType.ignore:
//To Be Implemented
break;
case ErrorTypes.errorType.popup:
//To Be Implemented
break;
case ErrorTypes.errorType.redirect:
NavigationManager.NavigateTo("/");
break;
}
}
}
}