Skip to content

Commit

Permalink
Fixes #2288 make SetNavigationServiceForPage protected
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Jan 28, 2021
1 parent 5d37175 commit 96aa296
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Forms/Prism.Forms/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,19 +859,15 @@ protected virtual Page CreatePageFromSegment(string segment)
return page;
}

private Page SetNavigationServiceForPage(Page page)
/// <summary>
/// Ensures that the <see cref="Page"/> has an attached <see cref="IScopedProvider"/> and <see cref="INavigationService"/>
/// that can be more easily reused.
/// </summary>
/// <param name="page">The <see cref="Page"/> the <see cref="INavigationService"/> instance will be created for.</param>
/// <returns>The <see cref="Page"/></returns>
protected Page SetNavigationServiceForPage(Page page)
{
// Someone explicitly set Autowire ViewModel
if (page.GetValue(Xaml.Navigation.NavigationServiceProperty) != null)
return page;

// This will wireup the Navigation Service in case you have something injected that
// actually required the Nav Service
var childNavService = _container.Resolve<INavigationService>();
if (childNavService is IPageAware pa)
pa.Page = page;

page.SetValue(Xaml.Navigation.NavigationServiceProperty, childNavService);
Xaml.Navigation.GetNavigationService(page);
return page;
}

Expand Down

0 comments on commit 96aa296

Please sign in to comment.