Skip to content

Commit

Permalink
Remove ILoggerFacade from PageNavigationService
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Aug 21, 2020
1 parent 522799b commit 1a355be
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 127 deletions.
48 changes: 18 additions & 30 deletions src/Forms/Prism.Forms/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Prism.Behaviors;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -25,7 +24,6 @@ public class PageNavigationService : INavigationService, IPlatformNavigationServ
private readonly IContainerProvider _container;
protected readonly IApplicationProvider _applicationProvider;
protected readonly IPageBehaviorFactory _pageBehaviorFactory;
protected readonly ILoggerFacade _logger;

protected Page _page;
Page IPageAware.Page
Expand All @@ -34,12 +32,17 @@ Page IPageAware.Page
set { _page = value; }
}

public PageNavigationService(IContainerProvider container, IApplicationProvider applicationProvider, IPageBehaviorFactory pageBehaviorFactory, ILoggerFacade logger)
/// <summary>
/// Constructs a new instance of the <see cref="PageNavigationService"/>.
/// </summary>
/// <param name="container">The <see cref="IContainerProvider"/> that will be used to resolve pages for navigation.</param>
/// <param name="applicationProvider">The <see cref="IApplicationProvider"/> that will let us ensure the Application.MainPage is set.</param>
/// <param name="pageBehaviorFactory">The <see cref="IPageBehaviorFactory"/> that will apply base and custom behaviors to pages created in the <see cref="PageNavigationService"/>.</param>
public PageNavigationService(IContainerProvider container, IApplicationProvider applicationProvider, IPageBehaviorFactory pageBehaviorFactory)
{
_container = container;
_applicationProvider = applicationProvider;
_pageBehaviorFactory = pageBehaviorFactory;
_logger = logger;
}

/// <summary>
Expand Down Expand Up @@ -108,7 +111,6 @@ protected async virtual Task<INavigationResult> GoBackInternal(INavigationParame
}
catch (Exception ex)
{
_logger.Log(ex.ToString(), Category.Exception, Priority.High);
result.Exception = ex;
return result;
}
Expand Down Expand Up @@ -325,7 +327,6 @@ protected async virtual Task<INavigationResult> NavigateInternal(Uri uri, INavig
}
catch (Exception ex)
{
_logger.Log(ex.ToString(), Category.Exception, Priority.High);
result.Exception = ex;
return result;
}
Expand Down Expand Up @@ -800,32 +801,19 @@ protected virtual Page CreatePage(string segmentName)

protected virtual Page CreatePageFromSegment(string segment)
{
string segmentName = null;
try
string segmentName = UriParsingHelper.GetSegmentName(segment);
var page = CreatePage(segmentName);
if (page == null)
{
segmentName = UriParsingHelper.GetSegmentName(segment);
var page = CreatePage(segmentName);
if (page == null)
{
var innerException = new NullReferenceException(string.Format("{0} could not be created. Please make sure you have registered {0} for navigation.", segmentName));
throw new NavigationException(NavigationException.NoPageIsRegistered, _page, innerException);
}
var innerException = new NullReferenceException(string.Format("{0} could not be created. Please make sure you have registered {0} for navigation.", segmentName));
throw new NavigationException(NavigationException.NoPageIsRegistered, _page, innerException);
}

PageUtilities.SetAutowireViewModelOnPage(page);
_pageBehaviorFactory.ApplyPageBehaviors(page);
ConfigurePages(page, segment);
PageUtilities.SetAutowireViewModelOnPage(page);
_pageBehaviorFactory.ApplyPageBehaviors(page);
ConfigurePages(page, segment);

return page;
}
catch(NavigationException)
{
throw;
}
catch (Exception e)
{
_logger.Log(e.ToString(), Category.Exception, Priority.High);
throw;
}
return page;
}

private Page SetNavigationServiceForPage(Page page)
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/MockApp/MockPrismApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override void Initialize()
MockContainer.Setup(x => x.Resolve(typeof(IModuleCatalog)))
.Returns(new ModuleCatalog());
MockContainer.Setup(x => x.Resolve(typeof(INavigationService), NavigationServiceName))
.Returns(new PageNavigationService(MockContainer.Object, this, new PageBehaviorFactory(), new EmptyLogger()));
.Returns(new PageNavigationService(MockContainer.Object, this, new PageBehaviorFactory()));
base.Initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Prism.DI.Forms.Tests.Navigation
{
public class CustomNavigationServiceMock : PageNavigationService
{
public CustomNavigationServiceMock(IContainerExtension container, IApplicationProvider applicationProvider, IPageBehaviorFactory pageBehaviorFactory, ILoggerFacade logger)
: base(container, applicationProvider, pageBehaviorFactory, logger)
public CustomNavigationServiceMock(IContainerExtension container, IApplicationProvider applicationProvider, IPageBehaviorFactory pageBehaviorFactory)
: base(container, applicationProvider, pageBehaviorFactory)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class PageNavigationServiceMock : PageNavigationService
IContainerExtension _containerMock;
PageNavigationEventRecorder _recorder;

public PageNavigationServiceMock(IContainerExtension containerMock, IApplicationProvider applicationProviderMock, ILoggerFacade loggerFacadeMock, PageNavigationEventRecorder recorder = null)
: base(containerMock, applicationProviderMock, new PageBehaviorFactory(), loggerFacadeMock)
public PageNavigationServiceMock(IContainerExtension containerMock, IApplicationProvider applicationProviderMock, PageNavigationEventRecorder recorder = null)
: base(containerMock, applicationProviderMock, new PageBehaviorFactory())
{
_containerMock = containerMock;
_recorder = recorder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class NavigationPathPageMock : ContentPage
public NavigationPathPageMockViewModel ViewModel { get; }
public NavigationPathPageMock()
{
var navService = new PageNavigationServiceMock(null, new ApplicationProviderMock(), null, null);
var navService = new PageNavigationServiceMock(null, new ApplicationProviderMock(), null);
((IPageAware)navService).Page = this;

BindingContext = ViewModel = new NavigationPathPageMockViewModel(navService);
Expand Down Expand Up @@ -47,7 +47,7 @@ public class NavigationPathTabbedPageMock : TabbedPage

public NavigationPathTabbedPageMock()
{
var navService = new PageNavigationServiceMock(null, new ApplicationProviderMock(), null, null);
var navService = new PageNavigationServiceMock(null, new ApplicationProviderMock(), null);
((IPageAware)navService).Page = this;

BindingContext = ViewModel = new NavigationPathPageMockViewModel(navService);
Expand Down
Loading

0 comments on commit 1a355be

Please sign in to comment.