Skip to content

Instantly share code, notes, and snippets.

@roubachof
Created December 24, 2021 15:56
Show Gist options
  • Save roubachof/b127000a91e5054dfd73179344da2ecc to your computer and use it in GitHub Desktop.
Save roubachof/b127000a91e5054dfd73179344da2ecc to your computer and use it in GitHub Desktop.
Prism Navigation service with exceptions raised
namespace MyCompany
{
public partial class App
{
public App(IPlatformInitializer initializer)
: base(initializer)
{
}
protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
{
base.RegisterRequiredTypes(containerRegistry);
containerRegistry.RegisterScoped<INavigationService, PageNavigationRaisingExceptionService>();
containerRegistry.Register<INavigationService, PageNavigationRaisingExceptionService>(NavigationServiceName);
}
}
}
using System;
using System.Threading.Tasks;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Navigation;
namespace MyCompany.Navigation;
public class PageNavigationRaisingExceptionService : PageNavigationService
{
public PageNavigationRaisingExceptionService(
IContainerProvider container,
IApplicationProvider applicationProvider,
IPageBehaviorFactory pageBehaviorFactory)
: base(container, applicationProvider, pageBehaviorFactory)
{
}
protected override async Task<INavigationResult> GoBackInternal(
INavigationParameters parameters,
bool? useModalNavigation,
bool animated)
{
var result = await base.GoBackInternal(parameters, useModalNavigation, animated);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
protected override async Task<INavigationResult> GoBackToRootInternal(INavigationParameters parameters)
{
var result = await base.GoBackToRootInternal(parameters);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
protected override async Task<INavigationResult> NavigateInternal(
Uri uri,
INavigationParameters parameters,
bool? useModalNavigation,
bool animated)
{
var result = await base.NavigateInternal(uri, parameters, useModalNavigation, animated);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment