From eba083ee046857b7645189f87da303c0ea97fcd8 Mon Sep 17 00:00:00 2001 From: Brian Lagunas Date: Tue, 21 Apr 2020 11:23:06 -0600 Subject: [PATCH 1/4] Added new PrismBootstrapper API --- e2e/Wpf/HelloWorld.Bootstraper/App.xaml | 7 + e2e/Wpf/HelloWorld.Bootstraper/App.xaml.cs | 18 ++ .../HelloWorld.Bootstraper/Bootstrapper.cs | 21 ++ .../HelloWorld.Bootstrapper.csproj | 16 ++ .../ViewModels/MainWindowViewModel.cs | 16 ++ .../Views/MainWindow.xaml | 9 + .../Views/MainWindow.xaml.cs | 15 ++ e2e/Wpf/HelloWorld.sln | 10 +- src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs | 27 +++ src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs | 19 ++ src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs | 216 ++++++++++++++++++ 11 files changed, 372 insertions(+), 2 deletions(-) create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/App.xaml create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/App.xaml.cs create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml create mode 100644 e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs create mode 100644 src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs create mode 100644 src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs create mode 100644 src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs diff --git a/e2e/Wpf/HelloWorld.Bootstraper/App.xaml b/e2e/Wpf/HelloWorld.Bootstraper/App.xaml new file mode 100644 index 0000000000..df462fee02 --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/App.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/e2e/Wpf/HelloWorld.Bootstraper/App.xaml.cs b/e2e/Wpf/HelloWorld.Bootstraper/App.xaml.cs new file mode 100644 index 0000000000..297f93d3cd --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/App.xaml.cs @@ -0,0 +1,18 @@ +using System.Windows; + +namespace HelloWorld +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + var bs = new Bootstrapper(); + bs.Run(); + } + } +} diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs new file mode 100644 index 0000000000..d4910e60eb --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs @@ -0,0 +1,21 @@ +using HelloWorld.Views; +using Prism.Ioc; +using Prism.Unity; +using System.Windows; +using Unity; + +namespace HelloWorld +{ + class Bootstrapper : PrismBootstrapper + { + protected override Window CreateShell() + { + return Container.Resolve(); + } + + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + + } + } +} \ No newline at end of file diff --git a/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj b/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj new file mode 100644 index 0000000000..3c611728ec --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj @@ -0,0 +1,16 @@ + + + + WinExe + netcoreapp3.1 + true + HelloWorld + + + + + + + + + \ No newline at end of file diff --git a/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs b/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000000..36703653bc --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,16 @@ +using Prism.Commands; +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace HelloWorld.ViewModels +{ + public class MainWindowViewModel : BindableBase + { + public MainWindowViewModel() + { + + } + } +} diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml new file mode 100644 index 0000000000..fdb4280eef --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs new file mode 100644 index 0000000000..8c68cab493 --- /dev/null +++ b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows; + +namespace HelloWorld.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/e2e/Wpf/HelloWorld.sln b/e2e/Wpf/HelloWorld.sln index e1190864a0..0dec76be35 100644 --- a/e2e/Wpf/HelloWorld.sln +++ b/e2e/Wpf/HelloWorld.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28729.10 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld\HelloWorld.csproj", "{B03C14CC-8DE9-40EE-9562-12B976E4CEE8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorld", "HelloWorld\HelloWorld.csproj", "{B03C14CC-8DE9-40EE-9562-12B976E4CEE8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism", "..\..\src\Prism.Core\Prism.Core.csproj", "{457AA668-72BB-4701-9A4E-FA86B0C412DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Core", "..\..\src\Prism.Core\Prism.Core.csproj", "{457AA668-72BB-4701-9A4E-FA86B0C412DE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Prism Library", "Prism Library", "{15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A}" EndProject @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.DryIoc.Wpf", "..\..\s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Unity.Wpf", "..\..\src\Wpf\Prism.Unity.Wpf\Prism.Unity.Wpf.csproj", "{DEBADAAB-5C78-444E-AA77-336A43B49EC3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Bootstrapper", "HelloWorld.Bootstraper\HelloWorld.Bootstrapper.csproj", "{36C11381-D25A-4E40-956F-05E9C440FA86}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,10 @@ Global {DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU {DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEBADAAB-5C78-444E-AA77-336A43B49EC3}.Release|Any CPU.Build.0 = Release|Any CPU + {36C11381-D25A-4E40-956F-05E9C440FA86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36C11381-D25A-4E40-956F-05E9C440FA86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36C11381-D25A-4E40-956F-05E9C440FA86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36C11381-D25A-4E40-956F-05E9C440FA86}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs b/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs new file mode 100644 index 0000000000..8e17a86d7e --- /dev/null +++ b/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs @@ -0,0 +1,27 @@ +using DryIoc; +using Prism.Ioc; +using System; + +namespace Prism.DryIoc +{ + public abstract class PrismBootstrapper : PrismBootstrapperBase + { + /// + /// Create to alter behavior of + /// + /// An instance of + protected virtual Rules CreateContainerRules() => Rules.Default.WithAutoConcreteTypeResolution() + .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)) + .WithDefaultIfAlreadyRegistered(IfAlreadyRegistered.Replace); + + protected override IContainerExtension CreateContainerExtension() + { + return new DryIocContainerExtension(new Container(CreateContainerRules())); + } + + protected override void RegisterFrameworkExceptionTypes() + { + ExceptionExtensions.RegisterFrameworkExceptionType(typeof(ContainerException)); + } + } +} diff --git a/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs b/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs new file mode 100644 index 0000000000..817bd32e52 --- /dev/null +++ b/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs @@ -0,0 +1,19 @@ +using Prism.Ioc; +using System; +using Unity; + +namespace Prism.Unity +{ + public abstract class PrismBootstrapper : PrismBootstrapperBase + { + protected override IContainerExtension CreateContainerExtension() + { + return new UnityContainerExtension(); + } + + protected override void RegisterFrameworkExceptionTypes() + { + ExceptionExtensions.RegisterFrameworkExceptionType(typeof(ResolutionFailedException)); + } + } +} diff --git a/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs new file mode 100644 index 0000000000..feeaca55dd --- /dev/null +++ b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs @@ -0,0 +1,216 @@ +using Prism.Events; +using Prism.Ioc; +using Prism.Logging; +using Prism.Modularity; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Regions.Behaviors; +using Prism.Services.Dialogs; +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace Prism +{ + public abstract class PrismBootstrapperBase + { + IContainerExtension _containerExtension; + IModuleCatalog _moduleCatalog; + + /// + /// The dependency injection container used to resolve objects + /// + public IContainerProvider Container => _containerExtension; + + /// + /// Gets the shell user interface + /// + /// The shell user interface. + protected Window Shell { get; set; } + + + public void Run() + { + InitializeInternal(); + } + + /// + /// Run the initialization process. + /// + void InitializeInternal() + { + ConfigureViewModelLocator(); + Initialize(); + OnInitialized(); + } + + /// + /// Configures the used by Prism. + /// + protected virtual void ConfigureViewModelLocator() + { + ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) => + { + return Container.Resolve(type); + }); + } + + /// + /// Runs the initialization sequence to configure the Prism application. + /// + public virtual void Initialize() + { + ContainerLocator.SetContainerExtension(CreateContainerExtension); + _containerExtension = ContainerLocator.Current; + _moduleCatalog = CreateModuleCatalog(); + RegisterRequiredTypes(_containerExtension); + RegisterTypes(_containerExtension); + _containerExtension.FinalizeExtension(); + + ConfigureModuleCatalog(_moduleCatalog); + + var regionAdapterMappins = _containerExtension.Resolve(); + ConfigureRegionAdapterMappings(regionAdapterMappins); + + var defaultRegionBehaviors = _containerExtension.Resolve(); + ConfigureDefaultRegionBehaviors(defaultRegionBehaviors); + + RegisterFrameworkExceptionTypes(); + + var shell = CreateShell(); + if (shell != null) + { + RegionManager.SetRegionManager(shell, _containerExtension.Resolve()); + RegionManager.UpdateRegions(); + InitializeShell(shell); + } + + InitializeModules(); + } + + /// + /// Creates the container used by Prism. + /// + /// The container + protected abstract IContainerExtension CreateContainerExtension(); + + /// + /// Creates the used by Prism. + /// + /// + /// The base implementation returns a new ModuleCatalog. + /// + protected virtual IModuleCatalog CreateModuleCatalog() + { + return new ModuleCatalog(); + } + + /// + /// Registers all types that are required by Prism to function with the container. + /// + /// + protected virtual void RegisterRequiredTypes(IContainerRegistry containerRegistry) + { + containerRegistry.RegisterInstance(_moduleCatalog); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + containerRegistry.Register(); + containerRegistry.Register(); + containerRegistry.Register(); + containerRegistry.Register(); //default dialog host + } + + /// + /// Used to register types with the container that will be used by your application. + /// + protected abstract void RegisterTypes(IContainerRegistry containerRegistry); + + /// + /// Configures the . + /// This will be the list of default behaviors that will be added to a region. + /// + 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)); + } + } + + /// + /// Configures the default region adapter mappings to use in the application, in order + /// to adapt UI controls defined in XAML to use a region and register it automatically. + /// May be overwritten in a derived class to add specific mappings required by the application. + /// + /// The instance containing all the mappings. + protected virtual void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) + { + if (regionAdapterMappings != null) + { + regionAdapterMappings.RegisterMapping(typeof(Selector), _containerExtension.Resolve()); + regionAdapterMappings.RegisterMapping(typeof(ItemsControl), _containerExtension.Resolve()); + regionAdapterMappings.RegisterMapping(typeof(ContentControl), _containerExtension.Resolve()); + } + } + + /// + /// Registers the s of the Exceptions that are not considered + /// root exceptions by the . + /// + protected virtual void RegisterFrameworkExceptionTypes() + { + } + + /// + /// Creates the shell or main window of the application. + /// + /// The shell of the application. + protected abstract Window CreateShell(); + + /// + /// Initializes the shell. + /// + protected virtual void InitializeShell(Window shell) + { + Shell = shell; + } + + /// + /// Contains actions that should occur last. + /// + protected virtual void OnInitialized() + { + Shell?.Show(); + } + + /// + /// Configures the used by Prism. + /// + protected virtual void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { } + + /// + /// Initializes the modules. + /// + protected virtual void InitializeModules() + { + IModuleManager manager = _containerExtension.Resolve(); + manager.Run(); + } + } +} From 21266d63ac102246bd6428276dfb3aa1f05e8452 Mon Sep 17 00:00:00 2001 From: Brian Lagunas Date: Tue, 21 Apr 2020 12:36:54 -0600 Subject: [PATCH 2/4] Updated sample to be cross "app/bootstrapper" compatible --- .../HelloWorld.Bootstraper/Bootstrapper.cs | 12 ++++- .../HelloWorld.Bootstrapper.csproj | 11 +++++ .../ViewModels/MainWindowViewModel.cs | 16 ------- .../Views/MainWindow.xaml | 9 ---- .../Views/MainWindow.xaml.cs | 15 ------- .../DialogServiceExtensions.cs | 23 ++++++++++ .../HelloWorld.Core/HelloWorld.Core.csproj | 13 ++++++ e2e/Wpf/HelloWorld.sln | 15 +++++++ e2e/Wpf/HelloWorld/App.xaml.cs | 18 ++++---- e2e/Wpf/HelloWorld/HelloWorld.csproj | 2 + .../HelloWorld/SharedSampleRegistrations.cs | 18 ++++++++ .../ViewModels/MainWindowViewModel.cs | 17 +------ e2e/Wpf/HelloWorld/Views/MainWindow.xaml | 10 +++-- e2e/Wpf/HelloWorld/Views/ViewA.xaml | 12 ----- e2e/Wpf/HelloWorld/Views/ViewA.xaml.cs | 44 ------------------- .../HelloWorld.Modules.ModuleA.csproj | 14 ++++++ .../ModuleAModule.cs | 19 ++++++++ .../ViewModels/ViewAViewModel.cs | 40 +++++++++++++++++ .../Views/ViewA.xaml | 14 ++++++ .../Views/ViewA.xaml.cs | 15 +++++++ 20 files changed, 209 insertions(+), 128 deletions(-) delete mode 100644 e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs delete mode 100644 e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml delete mode 100644 e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs create mode 100644 e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs create mode 100644 e2e/Wpf/HelloWorld.Core/HelloWorld.Core.csproj create mode 100644 e2e/Wpf/HelloWorld/SharedSampleRegistrations.cs delete mode 100644 e2e/Wpf/HelloWorld/Views/ViewA.xaml delete mode 100644 e2e/Wpf/HelloWorld/Views/ViewA.xaml.cs create mode 100644 e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/HelloWorld.Modules.ModuleA.csproj create mode 100644 e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ModuleAModule.cs create mode 100644 e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ViewModels/ViewAViewModel.cs create mode 100644 e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/Views/ViewA.xaml create mode 100644 e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/Views/ViewA.xaml.cs diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs index d4910e60eb..7118f77575 100644 --- a/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs +++ b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs @@ -1,5 +1,7 @@ -using HelloWorld.Views; +using HelloWorld.Modules.ModuleA; +using HelloWorld.Views; using Prism.Ioc; +using Prism.Modularity; using Prism.Unity; using System.Windows; using Unity; @@ -15,7 +17,13 @@ protected override Window CreateShell() protected override void RegisterTypes(IContainerRegistry containerRegistry) { - + containerRegistry.RegisterSharedSamples(); + } + + protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) + { + base.ConfigureModuleCatalog(moduleCatalog); + moduleCatalog.AddModule(); } } } \ No newline at end of file diff --git a/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj b/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj index 3c611728ec..db818883e7 100644 --- a/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj +++ b/e2e/Wpf/HelloWorld.Bootstraper/HelloWorld.Bootstrapper.csproj @@ -7,10 +7,21 @@ HelloWorld + + ..\HelloWorld\bin\**;..\HelloWorld\obj\**;..\HelloWorld\App.* + + + + + + + + + \ No newline at end of file diff --git a/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs b/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs deleted file mode 100644 index 36703653bc..0000000000 --- a/e2e/Wpf/HelloWorld.Bootstraper/ViewModels/MainWindowViewModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Prism.Commands; -using Prism.Mvvm; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace HelloWorld.ViewModels -{ - public class MainWindowViewModel : BindableBase - { - public MainWindowViewModel() - { - - } - } -} diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml deleted file mode 100644 index fdb4280eef..0000000000 --- a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs b/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs deleted file mode 100644 index 8c68cab493..0000000000 --- a/e2e/Wpf/HelloWorld.Bootstraper/Views/MainWindow.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Windows; - -namespace HelloWorld.Views -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - } - } -} diff --git a/e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs b/e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs new file mode 100644 index 0000000000..5d293fa51d --- /dev/null +++ b/e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs @@ -0,0 +1,23 @@ +using Prism.Services.Dialogs; +using System; + +namespace HelloWorld.Core +{ + public static class DialogServiceExtensions + { + public static void ShowNotification(this IDialogService dialogService, string message, Action callBack) + { + dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack); + } + + public static void ShowConfirmation(this IDialogService dialogService, string message, Action callBack) + { + dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack); + } + + public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action callBack) + { + dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow"); + } + } +} diff --git a/e2e/Wpf/HelloWorld.Core/HelloWorld.Core.csproj b/e2e/Wpf/HelloWorld.Core/HelloWorld.Core.csproj new file mode 100644 index 0000000000..dda708b0f8 --- /dev/null +++ b/e2e/Wpf/HelloWorld.Core/HelloWorld.Core.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp3.1 + true + + + + + + + + diff --git a/e2e/Wpf/HelloWorld.sln b/e2e/Wpf/HelloWorld.sln index 0dec76be35..128596a495 100644 --- a/e2e/Wpf/HelloWorld.sln +++ b/e2e/Wpf/HelloWorld.sln @@ -17,6 +17,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Unity.Wpf", "..\..\sr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Bootstrapper", "HelloWorld.Bootstraper\HelloWorld.Bootstrapper.csproj", "{36C11381-D25A-4E40-956F-05E9C440FA86}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Modules.ModuleA", "Modules\HelloWorld.Modules.ModuleA\HelloWorld.Modules.ModuleA.csproj", "{D16AADD5-6EAA-446A-83F5-9DFC36DD4108}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Core", "HelloWorld.Core\HelloWorld.Core.csproj", "{F9541A8C-42DD-4340-AB57-54C7AAAC1BCC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{63541838-3D6A-4F2E-92EF-AC4953BB9B9B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +53,14 @@ Global {36C11381-D25A-4E40-956F-05E9C440FA86}.Debug|Any CPU.Build.0 = Debug|Any CPU {36C11381-D25A-4E40-956F-05E9C440FA86}.Release|Any CPU.ActiveCfg = Release|Any CPU {36C11381-D25A-4E40-956F-05E9C440FA86}.Release|Any CPU.Build.0 = Release|Any CPU + {D16AADD5-6EAA-446A-83F5-9DFC36DD4108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D16AADD5-6EAA-446A-83F5-9DFC36DD4108}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D16AADD5-6EAA-446A-83F5-9DFC36DD4108}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D16AADD5-6EAA-446A-83F5-9DFC36DD4108}.Release|Any CPU.Build.0 = Release|Any CPU + {F9541A8C-42DD-4340-AB57-54C7AAAC1BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9541A8C-42DD-4340-AB57-54C7AAAC1BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9541A8C-42DD-4340-AB57-54C7AAAC1BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9541A8C-42DD-4340-AB57-54C7AAAC1BCC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,6 +70,7 @@ Global {AA8ED3D6-A708-4187-8FAC-00F56E063AD7} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A} {A0842858-BFD5-41AE-BDE7-CBD870BC9900} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A} {DEBADAAB-5C78-444E-AA77-336A43B49EC3} = {15CF1FE1-D78E-4E3D-A9F8-FA0FCC56A83A} + {D16AADD5-6EAA-446A-83F5-9DFC36DD4108} = {63541838-3D6A-4F2E-92EF-AC4953BB9B9B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D877B086-37FD-4AA5-8AB3-CF7E87E27425} diff --git a/e2e/Wpf/HelloWorld/App.xaml.cs b/e2e/Wpf/HelloWorld/App.xaml.cs index 53f1940408..70beeb03d8 100644 --- a/e2e/Wpf/HelloWorld/App.xaml.cs +++ b/e2e/Wpf/HelloWorld/App.xaml.cs @@ -1,7 +1,8 @@ using HelloWorld.Views; using Prism.Ioc; using System.Windows; -using HelloWorld.Dialogs; +using Prism.Modularity; +using HelloWorld.Modules.ModuleA; namespace HelloWorld { @@ -15,18 +16,15 @@ protected override Window CreateShell() return Container.Resolve(); } - public static string ViewAName = "MyViewA"; - protected override void RegisterTypes(IContainerRegistry containerRegistry) { - containerRegistry.RegisterForNavigation(ViewAName); - - containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); + containerRegistry.RegisterSharedSamples(); + } - //register a custom window host - containerRegistry.RegisterDialogWindow(); - containerRegistry.RegisterDialogWindow(nameof(AnotherDialogWindow)); + protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) + { + base.ConfigureModuleCatalog(moduleCatalog); + moduleCatalog.AddModule(); } } } diff --git a/e2e/Wpf/HelloWorld/HelloWorld.csproj b/e2e/Wpf/HelloWorld/HelloWorld.csproj index 21b8f3502a..52282b4d32 100644 --- a/e2e/Wpf/HelloWorld/HelloWorld.csproj +++ b/e2e/Wpf/HelloWorld/HelloWorld.csproj @@ -18,6 +18,8 @@ + + \ No newline at end of file diff --git a/e2e/Wpf/HelloWorld/SharedSampleRegistrations.cs b/e2e/Wpf/HelloWorld/SharedSampleRegistrations.cs new file mode 100644 index 0000000000..d542d678db --- /dev/null +++ b/e2e/Wpf/HelloWorld/SharedSampleRegistrations.cs @@ -0,0 +1,18 @@ +using HelloWorld.Dialogs; +using Prism.Ioc; + +namespace HelloWorld +{ + static class SharedSampleRegistrations + { + public static void RegisterSharedSamples(this IContainerRegistry containerRegistry) + { + containerRegistry.RegisterDialog(); + containerRegistry.RegisterDialog(); + + //register a custom window host + containerRegistry.RegisterDialogWindow(); + containerRegistry.RegisterDialogWindow(nameof(AnotherDialogWindow)); + } + } +} diff --git a/e2e/Wpf/HelloWorld/ViewModels/MainWindowViewModel.cs b/e2e/Wpf/HelloWorld/ViewModels/MainWindowViewModel.cs index af35bca4f1..ad88c1946f 100644 --- a/e2e/Wpf/HelloWorld/ViewModels/MainWindowViewModel.cs +++ b/e2e/Wpf/HelloWorld/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ using System; +using HelloWorld.Core; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; @@ -93,21 +94,5 @@ private void ShowDialog() } } - public static class DialogServiceExtensions - { - public static void ShowNotification(this IDialogService dialogService, string message, Action callBack) - { - dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack); - } - public static void ShowConfirmation(this IDialogService dialogService, string message, Action callBack) - { - dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack); - } - - public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action callBack) - { - dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow"); - } - } } diff --git a/e2e/Wpf/HelloWorld/Views/MainWindow.xaml b/e2e/Wpf/HelloWorld/Views/MainWindow.xaml index ffefa1cdfc..8a14255440 100644 --- a/e2e/Wpf/HelloWorld/Views/MainWindow.xaml +++ b/e2e/Wpf/HelloWorld/Views/MainWindow.xaml @@ -11,10 +11,12 @@ - + + + diff --git a/e2e/Wpf/HelloWorld/Views/ViewA.xaml b/e2e/Wpf/HelloWorld/Views/ViewA.xaml deleted file mode 100644 index 3230ec6dd7..0000000000 --- a/e2e/Wpf/HelloWorld/Views/ViewA.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/e2e/Wpf/HelloWorld/Views/ViewA.xaml.cs b/e2e/Wpf/HelloWorld/Views/ViewA.xaml.cs deleted file mode 100644 index 733386a03a..0000000000 --- a/e2e/Wpf/HelloWorld/Views/ViewA.xaml.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Prism.Regions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace HelloWorld.Views -{ - /// - /// Interaction logic for ViewA.xaml - /// - public partial class ViewA : UserControl, INavigationAware - { - public ViewA() - { - InitializeComponent(); - } - - public bool IsNavigationTarget(NavigationContext navigationContext) - { - return false; - } - - public void OnNavigatedFrom(NavigationContext navigationContext) - { - - } - - public void OnNavigatedTo(NavigationContext navigationContext) - { - - } - } -} diff --git a/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/HelloWorld.Modules.ModuleA.csproj b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/HelloWorld.Modules.ModuleA.csproj new file mode 100644 index 0000000000..fe60d44de5 --- /dev/null +++ b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/HelloWorld.Modules.ModuleA.csproj @@ -0,0 +1,14 @@ + + + + netcoreapp3.1 + true + + + + + + + + + diff --git a/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ModuleAModule.cs b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ModuleAModule.cs new file mode 100644 index 0000000000..54dbd66457 --- /dev/null +++ b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ModuleAModule.cs @@ -0,0 +1,19 @@ +using HelloWorld.Modules.ModuleA.Views; +using Prism.Ioc; +using Prism.Modularity; + +namespace HelloWorld.Modules.ModuleA +{ + public class ModuleAModule : IModule + { + public void OnInitialized(IContainerProvider containerProvider) + { + + } + + public void RegisterTypes(IContainerRegistry containerRegistry) + { + containerRegistry.RegisterForNavigation(); + } + } +} diff --git a/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ViewModels/ViewAViewModel.cs b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ViewModels/ViewAViewModel.cs new file mode 100644 index 0000000000..abd88baaa6 --- /dev/null +++ b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/ViewModels/ViewAViewModel.cs @@ -0,0 +1,40 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using HelloWorld.Core; + +namespace HelloWorld.Modules.ModuleA.ViewModels +{ + public class ViewAViewModel : BindableBase + { + private string _message; + public string Message + { + get { return _message; } + set { SetProperty(ref _message, value); } + } + + private DelegateCommand _showDialogCommand; + private readonly IDialogService _dialogService; + + public DelegateCommand ShowDialogCommand => + _showDialogCommand ?? (_showDialogCommand = new DelegateCommand(ExecuteShowDialogCommand)); + + void ExecuteShowDialogCommand() + { + _dialogService.ShowNotification("Hello There!", r => + { + if (r.Result == ButtonResult.OK) + Message = "OK was clicked"; + else + Message = "Something else was clicked"; + }); + } + + public ViewAViewModel(IDialogService dialogService) + { + Message = "Hello from ViewA in Module A"; + _dialogService = dialogService; + } + } +} diff --git a/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/Views/ViewA.xaml b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/Views/ViewA.xaml new file mode 100644 index 0000000000..c1903d3868 --- /dev/null +++ b/e2e/Wpf/Modules/HelloWorld.Modules.ModuleA/Views/ViewA.xaml @@ -0,0 +1,14 @@ + + + + + + + +