Skip to content

Commit

Permalink
Align Uno PrismAppliationBase with common PrismInitializationExtensions
Browse files Browse the repository at this point in the history
Uses RegisterRequiredTypes, RegisterDefaultRegionBehaviors and RegisterDefaultRegionAdapterMappings.
  • Loading branch information
jeromelaban committed Apr 23, 2020
1 parent f85446c commit 3c916c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ItemGroup>
<Compile Remove="..\..\Wpf\Prism.DryIoc.Wpf\Legacy\DryIocBootstrapper.cs" />
<Compile Remove="..\..\Wpf\Prism.DryIoc.Wpf\Legacy\DryIocExtensions.cs" />
<Compile Remove="..\..\Wpf\Prism.DryIoc.Wpf\PrismBootstrapper.cs" />
<Compile Remove="..\..\Wpf\Prism.DryIoc.Wpf\Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Uno/Prism.Unity.Uno/Prism.Unity.Uno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Compile Remove="..\..\Wpf\Prism.Unity.Wpf\Legacy\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="..\..\Wpf\Prism.Unity.Wpf\PrismBootstrapper.cs" />
<Compile Remove="..\..\Wpf\Prism.Unity.Wpf\Properties\AssemblyInfo.cs" />
<Compile Remove="..\..\Wpf\Prism.Unity.Wpf\Properties\Settings.Designer.cs" />
</ItemGroup>
Expand Down
9 changes: 6 additions & 3 deletions src/Uno/Prism.Uno/Prism.Uno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Remove="..\..\Wpf\Prism.Wpf\Bootstrapper.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\Interactivity\InvokeCommandAction.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\PrismApplicationBase.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\PrismBootstrapperBase.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\Properties\AssemblyInfo.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\Properties\Resources.Designer.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\Properties\Settings.Designer.cs" />
Expand All @@ -48,9 +49,6 @@
<Compile Remove="..\..\Wpf\Prism.Wpf\Services\Dialogs\IDialogWindow.cs" />
<Compile Remove="..\..\Wpf\Prism.Wpf\Services\Dialogs\IDialogWindowExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="LinkerDefinition.mono.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Prism.Core\Prism.Core.csproj" />
</ItemGroup>
Expand All @@ -72,4 +70,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Services\Dialogs\DialogWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
</Project>
44 changes: 9 additions & 35 deletions src/Uno/Prism.Uno/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public abstract class PrismApplicationBase : Application
IContainerExtension _containerExtension;
IModuleCatalog _moduleCatalog;

public PrismApplicationBase()
{
Suspending += (s, e) => OnSuspending(e);
}

/// <summary>
/// The dependency injection container used to resolve objects
/// </summary>
Expand Down Expand Up @@ -92,8 +97,6 @@ public virtual void Initialize()
}

InitializeModules();

Suspending += (s, e) => OnSuspending(e);
}

/// <summary>
Expand All @@ -119,20 +122,7 @@ protected virtual IModuleCatalog CreateModuleCatalog()
/// <param name="containerRegistry"></param>
protected virtual void RegisterRequiredTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterInstance(_moduleCatalog);
containerRegistry.RegisterSingleton<ILoggerFacade, TextLogger>();
containerRegistry.RegisterSingleton<IDialogService, DialogService>();
containerRegistry.RegisterSingleton<IModuleInitializer, ModuleInitializer>();
containerRegistry.RegisterSingleton<IModuleManager, ModuleManager>();
containerRegistry.RegisterSingleton<RegionAdapterMappings>();
containerRegistry.RegisterSingleton<IRegionManager, RegionManager>();
containerRegistry.RegisterSingleton<IRegionNavigationContentLoader, RegionNavigationContentLoader>();
containerRegistry.RegisterSingleton<IEventAggregator, EventAggregator>();
containerRegistry.RegisterSingleton<IRegionViewRegistry, RegionViewRegistry>();
containerRegistry.RegisterSingleton<IRegionBehaviorFactory, RegionBehaviorFactory>();
containerRegistry.Register<IRegionNavigationJournalEntry, RegionNavigationJournalEntry>();
containerRegistry.Register<IRegionNavigationJournal, RegionNavigationJournal>();
containerRegistry.Register<IRegionNavigationService, RegionNavigationService>();
containerRegistry.RegisterRequiredTypes(_moduleCatalog);
}

/// <summary>
Expand All @@ -146,17 +136,7 @@ protected virtual void RegisterRequiredTypes(IContainerRegistry containerRegistr
/// </summary>
protected virtual void ConfigureDefaultRegionBehaviors(IRegionBehaviorFactory regionBehaviors)
{
if (regionBehaviors != null)
{
regionBehaviors.AddIfMissing(BindRegionContextToDependencyObjectBehavior.BehaviorKey, typeof(BindRegionContextToDependencyObjectBehavior));
regionBehaviors.AddIfMissing(RegionActiveAwareBehavior.BehaviorKey, typeof(RegionActiveAwareBehavior));
regionBehaviors.AddIfMissing(SyncRegionContextWithHostBehavior.BehaviorKey, typeof(SyncRegionContextWithHostBehavior));
regionBehaviors.AddIfMissing(RegionManagerRegistrationBehavior.BehaviorKey, typeof(RegionManagerRegistrationBehavior));
regionBehaviors.AddIfMissing(RegionMemberLifetimeBehavior.BehaviorKey, typeof(RegionMemberLifetimeBehavior));
regionBehaviors.AddIfMissing(ClearChildViewsRegionBehavior.BehaviorKey, typeof(ClearChildViewsRegionBehavior));
regionBehaviors.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey, typeof(AutoPopulateRegionBehavior));
regionBehaviors.AddIfMissing(IDestructibleRegionBehavior.BehaviorKey, typeof(IDestructibleRegionBehavior));
}
regionBehaviors?.RegisterDefaultRegionBehaviors();
}

/// <summary>
Expand All @@ -167,12 +147,7 @@ protected virtual void ConfigureDefaultRegionBehaviors(IRegionBehaviorFactory re
/// <returns>The <see cref="RegionAdapterMappings"/> instance containing all the mappings.</returns>
protected virtual void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
{
if (regionAdapterMappings != null)
{
regionAdapterMappings.RegisterMapping(typeof(Selector), _containerExtension.Resolve<SelectorRegionAdapter>());
regionAdapterMappings.RegisterMapping(typeof(ItemsControl), _containerExtension.Resolve<ItemsControlRegionAdapter>());
regionAdapterMappings.RegisterMapping(typeof(ContentControl), _containerExtension.Resolve<ContentControlRegionAdapter>());
}
regionAdapterMappings?.RegisterDefaultRegionAdapterMappings();
}

/// <summary>
Expand Down Expand Up @@ -215,8 +190,7 @@ protected virtual void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { }
/// </summary>
protected virtual void InitializeModules()
{
IModuleManager manager = _containerExtension.Resolve<IModuleManager>();
manager.Run();
PrismInitializationExtensions.RunModuleManager(Container);
}

protected virtual void OnSuspending(SuspendingEventArgs e)
Expand Down
6 changes: 6 additions & 0 deletions src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
using Prism.Regions;
using Prism.Regions.Behaviors;
using Prism.Services.Dialogs;

#if HAS_WINUI
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
#else
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
#endif

namespace Prism
{
Expand Down

0 comments on commit 3c916c3

Please sign in to comment.