Skip to content

Commit

Permalink
fixing names
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Apr 16, 2020
1 parent 4e3edcb commit 5fad681
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 73 deletions.
8 changes: 5 additions & 3 deletions src/Prism.Core/Ioc/ContainerLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Prism.Ioc
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ContainerLocator
{
// NOTE: We want to use Lazy Initialization in case the container is first created
// prior to Prism initializing which could be the case with Shiny
private static Lazy<IContainerExtension> _lazyContainer;

private static IContainerExtension _current;
Expand All @@ -32,7 +30,11 @@ public static class ContainerLocator
/// Sets the Container Factory to use if the Current <see cref="IContainerProvider" /> is null
/// </summary>
/// <param name="factory"></param>
public static void SetContainerFactory(Func<IContainerExtension> factory) =>
/// <remarks>
/// NOTE: We want to use Lazy Initialization in case the container is first created
/// prior to Prism initializing which could be the case with Shiny
/// </remarks>
public static void SetContainerExtension(Func<IContainerExtension> factory) =>
_lazyContainer = new Lazy<IContainerExtension>(factory);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void Run(bool runWithDefaultConfiguration)
throw new InvalidOperationException(Resources.NullDryIocContainerException);
}

ContainerLocator.SetContainerFactory(CreateContainerExtension);
ContainerLocator.SetContainerExtension(CreateContainerExtension);
ContainerExtension = ContainerLocator.Current;

Logger.Log(Resources.ConfiguringContainer, Category.Debug, Priority.Low);
Expand Down
3 changes: 1 addition & 2 deletions src/Wpf/Prism.Unity.Wpf/Legacy/UnityBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override void Run(bool runWithDefaultConfiguration)
throw new InvalidOperationException(Resources.NullUnityContainerException);
}

ContainerLocator.SetContainerFactory(CreateContainerExtension);
ContainerLocator.SetContainerExtension(CreateContainerExtension);
ContainerExtension = ContainerLocator.Current;

this.Logger.Log(Resources.ConfiguringContainer, Category.Debug, Priority.Low);
Expand Down Expand Up @@ -133,7 +133,6 @@ protected virtual void ConfigureContainer()
RegisterTypeIfMissing(typeof(IDialogService), typeof(DialogService), true);
RegisterTypeIfMissing(typeof(IDialogWindow), typeof(DialogWindow), false);

// RegisterTypeIfMissing(typeof(IServiceLocator), typeof(UnityServiceLocatorAdapter), true);
RegisterTypeIfMissing(typeof(IModuleInitializer), typeof(ModuleInitializer), true);
RegisterTypeIfMissing(typeof(IModuleManager), typeof(ModuleManager), true);
RegisterTypeIfMissing(typeof(RegionAdapterMappings), typeof(RegionAdapterMappings), true);
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf/Prism.Wpf/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected virtual void ConfigureViewModelLocator()
/// </summary>
public virtual void Initialize()
{
ContainerLocator.SetContainerFactory(CreateContainerExtension);
ContainerLocator.SetContainerExtension(CreateContainerExtension);
_containerExtension = ContainerLocator.Current;
_moduleCatalog = CreateModuleCatalog();
RegisterRequiredTypes(_containerExtension);
Expand Down
20 changes: 10 additions & 10 deletions src/Wpf/Prism.Wpf/Regions/RegionBehaviorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ namespace Prism.Regions
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "It is more of a factory than a collection")]
public class RegionBehaviorFactory : IRegionBehaviorFactory
{
private readonly IContainerProvider container;
private readonly Dictionary<string, Type> registeredBehaviors = new Dictionary<string, Type>();
private readonly IContainerProvider _container;
private readonly Dictionary<string, Type> _registeredBehaviors = new Dictionary<string, Type>();

/// <summary>
/// Initializes a new instance of <see cref="RegionBehaviorFactory"/>.
/// </summary>
/// <param name="container"><see cref="IContainerExtension"/> used to create the instance of the behavior from its <see cref="Type"/>.</param>
public RegionBehaviorFactory(IContainerExtension container)
{
this.container = container;
_container = container;
}

/// <summary>
Expand Down Expand Up @@ -51,12 +51,12 @@ public void AddIfMissing(string behaviorKey, Type behaviorType)
}

// Only add the behaviorKey if it doesn't already exists.
if (this.registeredBehaviors.ContainsKey(behaviorKey))
if (_registeredBehaviors.ContainsKey(behaviorKey))
{
return;
}

this.registeredBehaviors.Add(behaviorKey, behaviorType);
_registeredBehaviors.Add(behaviorKey, behaviorType);
}

/// <summary>
Expand All @@ -66,13 +66,13 @@ public void AddIfMissing(string behaviorKey, Type behaviorType)
/// <returns>A new instance of the behavior. </returns>
public IRegionBehavior CreateFromKey(string key)
{
if (!this.ContainsKey(key))
if (!ContainsKey(key))
{
throw new ArgumentException(
string.Format(Thread.CurrentThread.CurrentCulture, Resources.TypeWithKeyNotRegistered, key), nameof(key));
}

return (IRegionBehavior)this.container.Resolve(this.registeredBehaviors[key]);
return (IRegionBehavior)_container.Resolve(_registeredBehaviors[key]);
}


Expand All @@ -85,7 +85,7 @@ public IRegionBehavior CreateFromKey(string key)
/// <filterpriority>1</filterpriority>
public IEnumerator<string> GetEnumerator()
{
return this.registeredBehaviors.Keys.GetEnumerator();
return _registeredBehaviors.Keys.GetEnumerator();
}

/// <summary>
Expand All @@ -97,7 +97,7 @@ public IEnumerator<string> GetEnumerator()
/// <filterpriority>2</filterpriority>
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
return GetEnumerator();
}

/// <summary>
Expand All @@ -109,7 +109,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// </returns>
public bool ContainsKey(string behaviorKey)
{
return this.registeredBehaviors.ContainsKey(behaviorKey);
return _registeredBehaviors.ContainsKey(behaviorKey);
}
}
}
70 changes: 29 additions & 41 deletions src/Wpf/Prism.Wpf/Regions/RegionNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ namespace Prism.Regions
/// </summary>
public class RegionNavigationService : IRegionNavigationService
{
private readonly IContainerProvider container;
private readonly IRegionNavigationContentLoader regionNavigationContentLoader;
private readonly IRegionNavigationJournal journal;
private NavigationContext currentNavigationContext;
private readonly IContainerProvider _container;
private readonly IRegionNavigationContentLoader _regionNavigationContentLoader;
private NavigationContext _currentNavigationContext;

/// <summary>
/// Initializes a new instance of the <see cref="RegionNavigationService"/> class.
Expand All @@ -27,10 +26,10 @@ public class RegionNavigationService : IRegionNavigationService
/// <param name="journal">The journal.</param>
public RegionNavigationService(IContainerExtension container, IRegionNavigationContentLoader regionNavigationContentLoader, IRegionNavigationJournal journal)
{
this.container = container ?? throw new ArgumentNullException(nameof(container));
this.regionNavigationContentLoader = regionNavigationContentLoader ?? throw new ArgumentNullException(nameof(regionNavigationContentLoader));
this.journal = journal ?? throw new ArgumentNullException(nameof(journal));
this.journal.NavigationTarget = this;
_container = container ?? throw new ArgumentNullException(nameof(container));
_regionNavigationContentLoader = regionNavigationContentLoader ?? throw new ArgumentNullException(nameof(regionNavigationContentLoader));
Journal = journal ?? throw new ArgumentNullException(nameof(journal));
Journal.NavigationTarget = this;
}

/// <summary>
Expand All @@ -43,13 +42,7 @@ public RegionNavigationService(IContainerExtension container, IRegionNavigationC
/// Gets the journal.
/// </summary>
/// <value>The journal.</value>
public IRegionNavigationJournal Journal
{
get
{
return this.journal;
}
}
public IRegionNavigationJournal Journal { get; private set; }

/// <summary>
/// Raised when the region is about to be navigated to content.
Expand Down Expand Up @@ -105,11 +98,11 @@ public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallb

try
{
this.DoNavigate(target, navigationCallback, navigationParameters);
DoNavigate(target, navigationCallback, navigationParameters);
}
catch (Exception e)
{
this.NotifyNavigationFailed(new NavigationContext(this, target), navigationCallback, e);
NotifyNavigationFailed(new NavigationContext(this, target), navigationCallback, e);
}
}

Expand All @@ -118,16 +111,16 @@ private void DoNavigate(Uri source, Action<NavigationResult> navigationCallback,
if (source == null)
throw new ArgumentNullException(nameof(source));

if (this.Region == null)
if (Region == null)
throw new InvalidOperationException(Resources.NavigationServiceHasNoRegion);

this.currentNavigationContext = new NavigationContext(this, source, navigationParameters);
_currentNavigationContext = new NavigationContext(this, source, navigationParameters);

// starts querying the active views
RequestCanNavigateFromOnCurrentlyActiveView(
this.currentNavigationContext,
_currentNavigationContext,
navigationCallback,
this.Region.ActiveViews.ToArray(),
Region.ActiveViews.ToArray(),
0);
}

Expand All @@ -139,16 +132,15 @@ private void RequestCanNavigateFromOnCurrentlyActiveView(
{
if (currentViewIndex < activeViews.Length)
{
var vetoingView = activeViews[currentViewIndex] as IConfirmNavigationRequest;
if (vetoingView != null)
if (activeViews[currentViewIndex] is IConfirmNavigationRequest vetoingView)
{
// the current active view implements IConfirmNavigationRequest, request confirmation
// providing a callback to resume the navigation request
vetoingView.ConfirmNavigationRequest(
navigationContext,
canNavigate =>
{
if (this.currentNavigationContext == navigationContext && canNavigate)
if (_currentNavigationContext == navigationContext && canNavigate)
{
RequestCanNavigateFromOnCurrentlyActiveViewModel(
navigationContext,
Expand All @@ -158,7 +150,7 @@ private void RequestCanNavigateFromOnCurrentlyActiveView(
}
else
{
this.NotifyNavigationFailed(navigationContext, navigationCallback, null);
NotifyNavigationFailed(navigationContext, navigationCallback, null);
}
});
}
Expand All @@ -183,21 +175,17 @@ private void RequestCanNavigateFromOnCurrentlyActiveViewModel(
object[] activeViews,
int currentViewIndex)
{
var frameworkElement = activeViews[currentViewIndex] as FrameworkElement;

if (frameworkElement != null)
if (activeViews[currentViewIndex] is FrameworkElement frameworkElement)
{
var vetoingViewModel = frameworkElement.DataContext as IConfirmNavigationRequest;

if (vetoingViewModel != null)
if (frameworkElement.DataContext is IConfirmNavigationRequest vetoingViewModel)
{
// the data model for the current active view implements IConfirmNavigationRequest, request confirmation
// providing a callback to resume the navigation request
vetoingViewModel.ConfirmNavigationRequest(
navigationContext,
canNavigate =>
{
if (this.currentNavigationContext == navigationContext && canNavigate)
if (_currentNavigationContext == navigationContext && canNavigate)
{
RequestCanNavigateFromOnCurrentlyActiveView(
navigationContext,
Expand All @@ -207,7 +195,7 @@ private void RequestCanNavigateFromOnCurrentlyActiveViewModel(
}
else
{
this.NotifyNavigationFailed(navigationContext, navigationCallback, null);
NotifyNavigationFailed(navigationContext, navigationCallback, null);
}
});

Expand All @@ -229,21 +217,21 @@ private void ExecuteNavigation(NavigationContext navigationContext, object[] act
{
NotifyActiveViewsNavigatingFrom(navigationContext, activeViews);

object view = this.regionNavigationContentLoader.LoadContent(this.Region, navigationContext);
object view = _regionNavigationContentLoader.LoadContent(Region, navigationContext);

// Raise the navigating event just before activing the view.
this.RaiseNavigating(navigationContext);
RaiseNavigating(navigationContext);

this.Region.Activate(view);
Region.Activate(view);

// Update the navigation journal before notifying others of navigaton
IRegionNavigationJournalEntry journalEntry = this.container.Resolve<IRegionNavigationJournalEntry>();
IRegionNavigationJournalEntry journalEntry = _container.Resolve<IRegionNavigationJournalEntry>();
journalEntry.Uri = navigationContext.Uri;
journalEntry.Parameters = navigationContext.Parameters;

bool persistInHistory = PersistInHistory(view);

this.journal.RecordNavigation(journalEntry, persistInHistory);
Journal.RecordNavigation(journalEntry, persistInHistory);

// The view can be informed of navigation
Action<INavigationAware> action = (n) => n.OnNavigatedTo(navigationContext);
Expand All @@ -252,11 +240,11 @@ private void ExecuteNavigation(NavigationContext navigationContext, object[] act
navigationCallback(new NavigationResult(navigationContext, true));

// Raise the navigated event when navigation is completed.
this.RaiseNavigated(navigationContext);
RaiseNavigated(navigationContext);
}
catch (Exception e)
{
this.NotifyNavigationFailed(navigationContext, navigationCallback, e);
NotifyNavigationFailed(navigationContext, navigationCallback, e);
}
}

Expand All @@ -273,7 +261,7 @@ private void NotifyNavigationFailed(NavigationContext navigationContext, Action<
e != null ? new NavigationResult(navigationContext, e) : new NavigationResult(navigationContext, false);

navigationCallback(navigationResult);
this.RaiseNavigationFailed(navigationContext, e);
RaiseNavigationFailed(navigationContext, e);
}

private static void NotifyActiveViewsNavigatingFrom(NavigationContext navigationContext, object[] activeViews)
Expand Down
8 changes: 4 additions & 4 deletions tests/Prism.Core.Tests/Ioc/ContainerLocatorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ContainerLocatorFixture
public void FactoryCreatesContainerExtension()
{
Assert.Null(Prism.Ioc.ContainerLocator.Current);
Prism.Ioc.ContainerLocator.SetContainerFactory(() => new MockContainerExtension());
Prism.Ioc.ContainerLocator.SetContainerExtension(() => new MockContainerExtension());
Assert.NotNull(Prism.Ioc.ContainerLocator.Current);
}

Expand All @@ -30,7 +30,7 @@ public void ResetNullsCurrentContainer()
{
Prism.Ioc.ContainerLocator.ResetContainer();
Assert.Null(Prism.Ioc.ContainerLocator.Current);
Prism.Ioc.ContainerLocator.SetContainerFactory(() => new MockContainerExtension());
Prism.Ioc.ContainerLocator.SetContainerExtension(() => new MockContainerExtension());
Assert.NotNull(Prism.Ioc.ContainerLocator.Current);
Prism.Ioc.ContainerLocator.ResetContainer();
Assert.Null(Prism.Ioc.ContainerLocator.Current);
Expand All @@ -43,10 +43,10 @@ public void FactoryOnlySetsContainerOnce()
var container = new MockContainerExtension();
var container2 = new Mock2ContainerExtension();

Prism.Ioc.ContainerLocator.SetContainerFactory(() => container);
Prism.Ioc.ContainerLocator.SetContainerExtension(() => container);
Assert.Same(container, Prism.Ioc.ContainerLocator.Container);

Prism.Ioc.ContainerLocator.SetContainerFactory(() => container2);
Prism.Ioc.ContainerLocator.SetContainerExtension(() => container2);
Assert.IsNotType<Mock2ContainerExtension>(Prism.Ioc.ContainerLocator.Container);
Assert.Same(container, Prism.Ioc.ContainerLocator.Container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public RegionNavigationContentLoaderFixture()
_container.Register(typeof(IRegionNavigationContentLoader), RegionNavigationContentLoaderType);
_container.Register<IRegionNavigationJournal, RegionNavigationJournal>();
ContainerLocator.ResetContainer();
ContainerLocator.SetContainerFactory(() => _container);
ContainerLocator.SetContainerExtension(() => _container);
}

[StaFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ShouldForwardResolveToInnerContainer()

var containerExtension = new DryIocContainerExtension(mockContainer.Object);
ContainerLocator.ResetContainer();
ContainerLocator.SetContainerFactory(() => containerExtension);
ContainerLocator.SetContainerExtension(() => containerExtension);

var resolved = ContainerLocator.Container.Resolve(typeof(object));
mockContainer.Verify(c => c.Resolve(typeof(object), IfUnresolved.Throw));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void ShouldForwardResolveToInnerContainer()
mockContainer.Setup(c => c.Resolve(typeof(object), null, It.IsAny<ResolverOverride[]>())).Returns(myInstance);
var containerExtension = new UnityContainerExtension(mockContainer.Object);
ContainerLocator.ResetContainer();
ContainerLocator.SetContainerFactory(() => containerExtension);
ContainerLocator.SetContainerExtension(() => containerExtension);
var resolved = ContainerLocator.Container.Resolve(typeof(object));
mockContainer.Verify(c => c.Resolve(typeof(object), null, It.IsAny<ResolverOverride[]>()), Times.Once);
Assert.Same(myInstance, resolved);
Expand Down
Loading

0 comments on commit 5fad681

Please sign in to comment.