diff --git a/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs index 7118f77575..36b72084ea 100644 --- a/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs +++ b/e2e/Wpf/HelloWorld.Bootstraper/Bootstrapper.cs @@ -10,7 +10,7 @@ namespace HelloWorld { class Bootstrapper : PrismBootstrapper { - protected override Window CreateShell() + protected override DependencyObject CreateShell() { return Container.Resolve(); } diff --git a/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocBootstrapper.cs b/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocBootstrapper.cs deleted file mode 100644 index f3ba27ed76..0000000000 --- a/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocBootstrapper.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using System.Globalization; -using DryIoc; -using Prism.DryIoc.Properties; -using Prism.Events; -using Prism.Ioc; -using Prism.Modularity; -using Prism.Mvvm; -using Prism.Regions; -using Prism.Services.Dialogs; - -namespace Prism.DryIoc -{ - /// - /// Base class that provides a basic bootstrapping sequence that - /// registers most of the Prism Library assets - /// in an DryIoc . - /// - /// - /// This class must be overridden to provide application specific configuration. - /// - [Obsolete("It is recommended to use the new PrismApplication as the app's base class. This will require updating the App.xaml and App.xaml.cs files.", false)] - public abstract class DryIocBootstrapper : Bootstrapper - { - private bool _useDefaultConfiguration = true; - - /// - /// Gets the default DryIoc for the application. - /// - /// The default instance. - public IContainer Container { get; protected set; } - - /// - /// Run the bootstrapper process. - /// - /// If , registers default Prism Library services in the container. This is the default behavior. - public override void Run(bool runWithDefaultConfiguration) - { - _useDefaultConfiguration = runWithDefaultConfiguration; - - Log(Resources.LoggerCreatedSuccessfully); - - Log(Resources.CreatingModuleCatalog); - ModuleCatalog = CreateModuleCatalog(); - if (ModuleCatalog == null) - { - throw new InvalidOperationException(Resources.NullModuleCatalogException); - } - - Log(Resources.ConfiguringModuleCatalog); - ConfigureModuleCatalog(); - - Log(Resources.CreatingContainer); - Container = CreateContainer(); - if (Container == null) - { - throw new InvalidOperationException(Resources.NullDryIocContainerException); - } - - ContainerLocator.SetContainerExtension(CreateContainerExtension); - ContainerExtension = ContainerLocator.Current; - - Log(Resources.ConfiguringContainer); - ConfigureContainer(); - - Log(Resources.ConfiguringViewModelLocator); - ConfigureViewModelLocator(); - - Log(Resources.ConfiguringRegionAdapters); - ConfigureRegionAdapterMappings(); - - Log(Resources.ConfiguringDefaultRegionBehaviors); - ConfigureDefaultRegionBehaviors(); - - Log(Resources.RegisteringFrameworkExceptionTypes); - RegisterFrameworkExceptionTypes(); - - Log(Resources.CreatingShell); - Shell = CreateShell(); - if (Shell != null) - { - Log(Resources.SettingTheRegionManager); - RegionManager.SetRegionManager(Shell, Container.Resolve()); - - Log(Resources.UpdatingRegions); - RegionManager.UpdateRegions(); - - Log(Resources.InitializingShell); - InitializeShell(); - } - - if (Container.IsRegistered()) - { - Log(Resources.InitializingModules); - InitializeModules(); - } - - Log(Resources.BootstrapperSequenceCompleted); - } - - /// - /// Configures the used by Prism. - /// - protected override void ConfigureViewModelLocator() - { - ViewModelLocationProvider.SetDefaultViewModelFactory((type) => Container.Resolve(type)); - } - - /// - /// Configures the . - /// May be overwritten in a derived class to add specific type mappings required by the application. - /// - protected virtual void ConfigureContainer() - { - Container.UseInstance(ModuleCatalog); - - if (_useDefaultConfiguration) - { - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(false); - - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(true); - RegisterTypeIfMissing(false); - RegisterTypeIfMissing(false); - RegisterTypeIfMissing(false); - RegisterTypeIfMissing(true); - } - } - - /// - /// Creates the DryIoc that will be used as the default container. - /// - /// A new instance of . - protected virtual IContainer CreateContainer() - { - return new Container(DryIocContainerExtension.DefaultRules); - } - - /// - /// Create a new used by Prism. - /// - /// A new . - protected override IContainerExtension CreateContainerExtension() - { - return new DryIocContainerExtension(Container); - } - - /// - /// Initializes the modules. May be overwritten in a derived class to use a custom Modules Catalog - /// - protected override void InitializeModules() - { - IModuleManager manager; - - try - { - manager = Container.Resolve(); - } - catch (ContainerException ex) - { - if (ex.Message.Contains("IModuleCatalog")) - { - throw new InvalidOperationException(Resources.NullModuleCatalogException); - } - - throw; - } - - manager.Run(); - } - - /// - /// Registers a type in the container only if that type was not already registered. - /// - /// The interface type to register. - /// The type implementing the interface. - /// Registers the type as a singleton. - protected void RegisterTypeIfMissing(bool registerAsSingleton = false) where TTarget : TFrom - { - if(Container!=null && Container.IsRegistered()) - { - Log(string.Format(CultureInfo.CurrentCulture, Resources.TypeMappingAlreadyRegistered, typeof(TFrom).Name)); - } - else - { - if (registerAsSingleton) - { - Container.Register(Reuse.Singleton); - } - else - { - Container.Register(); - } - } - } - - /// - /// Registers a type in the container only if that type was not already registered. - /// - /// The interface type to register. - /// The type implementing the interface. - /// Registers the type as a singleton. - protected void RegisterTypeIfMissing(Type fromType, Type toType, bool registerAsSingleton) - { - if (fromType == null) - { - throw new ArgumentNullException(nameof(fromType)); - } - if (toType == null) - { - throw new ArgumentNullException(nameof(toType)); - } - if (Container.IsRegistered(fromType)) - { - Log(string.Format(CultureInfo.CurrentCulture, Resources.TypeMappingAlreadyRegistered, fromType.Name)); - } - else - { - if (registerAsSingleton) - { - Container.Register(fromType, toType, Reuse.Singleton); - } - else - { - Container.Register(fromType, toType); - } - } - } - } -} diff --git a/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocExtensions.cs b/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocExtensions.cs deleted file mode 100644 index 97eec201bf..0000000000 --- a/src/Wpf/Prism.DryIoc.Wpf/Legacy/DryIocExtensions.cs +++ /dev/null @@ -1,61 +0,0 @@ -using DryIoc; -using Prism.Mvvm; -using System; - -namespace Prism.DryIoc -{ - /// - /// extensions. - /// - public static class DryIocExtensions - { - /// - /// Registers an object for navigation. - /// - /// The Type of the object to register - /// The container instance - /// The unique name to register with the object - public static void RegisterTypeForNavigation(this IContainer container, string name = null) - { - Type type = typeof(T); - string viewName = string.IsNullOrWhiteSpace(name) ? type.Name : name; - container.RegisterTypeForNavigation(type, viewName); - } - - /// - /// Registers an object for navigation - /// - /// - /// The type of object to register - /// The unique name to register with the obect. - public static void RegisterTypeForNavigation(this IContainer container, Type type, string name) - { - container.Register(typeof(object), - type, - made: Made.Of(FactoryMethod.ConstructorWithResolvableArguments), - serviceKey: name); - } - - /// - /// Registers an object for navigation. - /// - /// The Type of object to register as the view - /// The ViewModel to use as the DataContext for the view - /// The unique name to register with the view - /// - public static void RegisterTypeForNavigation(this IContainer container, string name = null) - { - container.RegisterTypeForNavigationWithViewModel(typeof(TView), name); - } - - private static void RegisterTypeForNavigationWithViewModel(this IContainer container, Type viewType, string name = null) - { - if (string.IsNullOrWhiteSpace(name)) - name = viewType.Name; - - ViewModelLocationProvider.Register(viewType.ToString(), typeof(TViewModel)); - - container.RegisterTypeForNavigation(viewType, name); - } - } -} diff --git a/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.Designer.cs b/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.Designer.cs index bb2f8d44b9..b002ea5fa2 100644 --- a/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.Designer.cs +++ b/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.Designer.cs @@ -60,114 +60,6 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to Bootstrapper sequence completed.. - /// - internal static string BootstrapperSequenceCompleted { - get { - return ResourceManager.GetString("BootstrapperSequenceCompleted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring the DryIoc container.. - /// - internal static string ConfiguringContainer { - get { - return ResourceManager.GetString("ConfiguringContainer", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring default region behaviors.. - /// - internal static string ConfiguringDefaultRegionBehaviors { - get { - return ResourceManager.GetString("ConfiguringDefaultRegionBehaviors", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring module catalog.. - /// - internal static string ConfiguringModuleCatalog { - get { - return ResourceManager.GetString("ConfiguringModuleCatalog", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring region adapters.. - /// - internal static string ConfiguringRegionAdapters { - get { - return ResourceManager.GetString("ConfiguringRegionAdapters", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring the ViewModelLocator to use DryIoc.. - /// - internal static string ConfiguringViewModelLocator { - get { - return ResourceManager.GetString("ConfiguringViewModelLocator", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating DryIoc container.. - /// - internal static string CreatingContainer { - get { - return ResourceManager.GetString("CreatingContainer", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating module catalog.. - /// - internal static string CreatingModuleCatalog { - get { - return ResourceManager.GetString("CreatingModuleCatalog", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating the shell.. - /// - internal static string CreatingShell { - get { - return ResourceManager.GetString("CreatingShell", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Initializing modules.. - /// - internal static string InitializingModules { - get { - return ResourceManager.GetString("InitializingModules", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Initializing the shell.. - /// - internal static string InitializingShell { - get { - return ResourceManager.GetString("InitializingShell", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Logger was created successfully.. - /// - internal static string LoggerCreatedSuccessfully { - get { - return ResourceManager.GetString("LoggerCreatedSuccessfully", resourceCulture); - } - } - /// /// Looks up a localized string similar to The method 'GetModuleEnumerator' of the bootstrapper must be overwritten in order to use the default module initialization logic.. /// @@ -213,24 +105,6 @@ internal static string NullModuleCatalogException { } } - /// - /// Looks up a localized string similar to Registering Framework Exception Types.. - /// - internal static string RegisteringFrameworkExceptionTypes { - get { - return ResourceManager.GetString("RegisteringFrameworkExceptionTypes", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Setting the RegionManager.. - /// - internal static string SettingTheRegionManager { - get { - return ResourceManager.GetString("SettingTheRegionManager", resourceCulture); - } - } - /// /// Looks up a localized string similar to Type '{0}' was already registered by the application. Skipping.... /// @@ -239,14 +113,5 @@ internal static string TypeMappingAlreadyRegistered { return ResourceManager.GetString("TypeMappingAlreadyRegistered", resourceCulture); } } - - /// - /// Looks up a localized string similar to Updating Regions.. - /// - internal static string UpdatingRegions { - get { - return ResourceManager.GetString("UpdatingRegions", resourceCulture); - } - } } } diff --git a/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.resx b/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.resx index 282232225f..6e0c783977 100644 --- a/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.resx +++ b/src/Wpf/Prism.DryIoc.Wpf/Properties/Resources.resx @@ -117,42 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Bootstrapper sequence completed. - - - Configuring the DryIoc container. - - - Configuring default region behaviors. - - - Configuring module catalog. - - - Configuring region adapters. - - - Configuring the ViewModelLocator to use DryIoc. - - - Creating DryIoc container. - - - Creating module catalog. - - - Creating the shell. - - - Initializing modules. - - - Initializing the shell. - - - Logger was created successfully. - The method 'GetModuleEnumerator' of the bootstrapper must be overwritten in order to use the default module initialization logic. @@ -168,16 +132,7 @@ The IModuleCatalog is required and cannot be null in order to initialize the modules. - - Registering Framework Exception Types. - - - Setting the RegionManager. - Type '{0}' was already registered by the application. Skipping... - - Updating Regions. - \ No newline at end of file diff --git a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityBootstrapper.cs b/src/Wpf/Prism.Unity.Wpf/Legacy/UnityBootstrapper.cs deleted file mode 100644 index ba3ade042f..0000000000 --- a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityBootstrapper.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System; -using System.Globalization; -using Prism.Events; -using Prism.Ioc; -using Prism.Modularity; -using Prism.Regions; -using Prism.Services.Dialogs; -using Prism.Unity.Properties; -using Unity; -using Unity.Lifetime; - -namespace Prism.Unity -{ - /// - /// Base class that provides a basic bootstrapping sequence that - /// registers most of the Prism Library assets - /// in a . - /// - /// - /// This class must be overridden to provide application specific configuration. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")] - [Obsolete("It is recommended to use the new PrismApplication as the app's base class. This will require updating the App.xaml and App.xaml.cs files.", false)] - public abstract class UnityBootstrapper : Bootstrapper - { - private bool useDefaultConfiguration = true; - - /// - /// Gets the default for the application. - /// - /// The default instance. - public IUnityContainer Container { get; protected set; } - - - /// - /// Run the bootstrapper process. - /// - /// If , registers default Prism Library services in the container. This is the default behavior. - public override void Run(bool runWithDefaultConfiguration) - { - useDefaultConfiguration = runWithDefaultConfiguration; - - Log(Resources.LoggerCreatedSuccessfully); - - Log(Resources.CreatingModuleCatalog); - ModuleCatalog = CreateModuleCatalog(); - if (this.ModuleCatalog == null) - { - throw new InvalidOperationException(Resources.NullModuleCatalogException); - } - - Log(Resources.ConfiguringModuleCatalog); - this.ConfigureModuleCatalog(); - - Log(Resources.CreatingContainer); - this.Container = this.CreateContainer(); - if (this.Container == null) - { - throw new InvalidOperationException(Resources.NullUnityContainerException); - } - - ContainerLocator.SetContainerExtension(CreateContainerExtension); - ContainerExtension = ContainerLocator.Current; - - Log(Resources.ConfiguringContainer); - this.ConfigureContainer(); - - Log(Resources.ConfiguringViewModelLocator); - this.ConfigureViewModelLocator(); - - Log(Resources.ConfiguringRegionAdapters); - this.ConfigureRegionAdapterMappings(); - - Log(Resources.ConfiguringDefaultRegionBehaviors); - this.ConfigureDefaultRegionBehaviors(); - - Log(Resources.RegisteringFrameworkExceptionTypes); - this.RegisterFrameworkExceptionTypes(); - - Log(Resources.CreatingShell); - this.Shell = this.CreateShell(); - if (this.Shell != null) - { - Log(Resources.SettingTheRegionManager); - RegionManager.SetRegionManager(this.Shell, this.Container.Resolve()); - - Log(Resources.UpdatingRegions); - RegionManager.UpdateRegions(); - - Log(Resources.InitializingShell); - this.InitializeShell(); - } - - if (Container.IsRegistered()) - { - Log(Resources.InitializingModules); - InitializeModules(); - } - - Log(Resources.BootstrapperSequenceCompleted); - } - - /// - /// Configures the . May be overwritten in a derived class to add specific - /// type mappings required by the application. - /// - protected virtual void ConfigureContainer() - { - Container.RegisterInstance(ModuleCatalog); - - if (useDefaultConfiguration) - { - RegisterTypeIfMissing(typeof(IDialogService), typeof(DialogService), true); - RegisterTypeIfMissing(typeof(IDialogWindow), typeof(DialogWindow), false); - - RegisterTypeIfMissing(typeof(IModuleInitializer), typeof(ModuleInitializer), true); - RegisterTypeIfMissing(typeof(IModuleManager), typeof(ModuleManager), true); - RegisterTypeIfMissing(typeof(RegionAdapterMappings), typeof(RegionAdapterMappings), true); - RegisterTypeIfMissing(typeof(IRegionManager), typeof(RegionManager), true); - RegisterTypeIfMissing(typeof(IEventAggregator), typeof(EventAggregator), true); - RegisterTypeIfMissing(typeof(IRegionViewRegistry), typeof(RegionViewRegistry), true); - RegisterTypeIfMissing(typeof(IRegionBehaviorFactory), typeof(RegionBehaviorFactory), true); - RegisterTypeIfMissing(typeof(IRegionNavigationJournalEntry), typeof(RegionNavigationJournalEntry), false); - RegisterTypeIfMissing(typeof(IRegionNavigationJournal), typeof(RegionNavigationJournal), false); - RegisterTypeIfMissing(typeof(IRegionNavigationService), typeof(RegionNavigationService), false); - RegisterTypeIfMissing(typeof(IRegionNavigationContentLoader), typeof(RegionNavigationContentLoader), true); - } - } - - /// - /// Initializes the modules. May be overwritten in a derived class to use a custom Modules Catalog - /// - protected override void InitializeModules() - { - IModuleManager manager; - - try - { - manager = this.Container.Resolve(); - } - catch (ResolutionFailedException ex) - { - if (ex.Message.Contains("IModuleCatalog")) - { - throw new InvalidOperationException(Resources.NullModuleCatalogException); - } - - throw; - } - - manager.Run(); - } - - /// - /// Creates the that will be used as the default container. - /// - /// A new instance of . - protected virtual IUnityContainer CreateContainer() - { - return new UnityContainer(); - } - - /// - /// Creates the used by Prism. - /// - /// The container extension. - protected override IContainerExtension CreateContainerExtension() - { - return new UnityContainerExtension(Container); - } - - /// - /// Registers a type in the container only if that type was not already registered. - /// - /// The interface type to register. - /// The type implementing the interface. - /// Registers the type as a singleton. - protected void RegisterTypeIfMissing(Type fromType, Type toType, bool registerAsSingleton) - { - if (fromType == null) - { - throw new ArgumentNullException(nameof(fromType)); - } - if (toType == null) - { - throw new ArgumentNullException(nameof(toType)); - } - if (Container.IsTypeRegistered(fromType)) - { - Log( - string.Format(CultureInfo.CurrentCulture, - Resources.TypeMappingAlreadyRegistered, - fromType.Name)); - } - else - { - if (registerAsSingleton) - { - Container.RegisterType(fromType, toType, new ContainerControlledLifetimeManager()); - } - else - { - Container.RegisterType(fromType, toType); - } - } - } - } -} diff --git a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityContainerHelper.cs b/src/Wpf/Prism.Unity.Wpf/Legacy/UnityContainerHelper.cs deleted file mode 100644 index ce87aabe09..0000000000 --- a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityContainerHelper.cs +++ /dev/null @@ -1,60 +0,0 @@ - - -using System; -using Unity; - -namespace Prism.Unity -{ - /// - /// Extensions methods to extend and facilitate the usage of . - /// - public static class UnityContainerHelper - { - /// - /// Returns whether a specified type has a type mapping registered in the container. - /// - /// The to check for the type mapping. - /// The type to check if there is a type mapping for. - /// if there is a type mapping registered for . - public static bool IsTypeRegistered(this IUnityContainer container, Type type) - { - return container.IsRegistered(type); - } - - /// - /// Utility method to try to resolve a service from the container avoiding an exception if the container cannot build the type. - /// - /// The cointainer that will be used to resolve the type. - /// The type to resolve. - /// The instance of built up by the container. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - public static T TryResolve(this IUnityContainer container) - { - object result = TryResolve(container, typeof(T)); - if (result != null) - { - return (T)result; - } - return default(T); - } - - /// - /// Utility method to try to resolve a service from the container avoiding an exception if the container cannot build the type. - /// - /// The cointainer that will be used to resolve the type. - /// The type to resolve. - /// The instance of built up by the container. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] - public static object TryResolve(this IUnityContainer container, Type typeToResolve) - { - try - { - return container.Resolve(typeToResolve); - } - catch - { - return null; - } - } - } -} \ No newline at end of file diff --git a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityExtensions.cs b/src/Wpf/Prism.Unity.Wpf/Legacy/UnityExtensions.cs deleted file mode 100644 index cb8a34d2b6..0000000000 --- a/src/Wpf/Prism.Unity.Wpf/Legacy/UnityExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Unity; -using System; -using Prism.Mvvm; - -namespace Prism.Unity -{ - /// - /// extensions. - /// - public static class UnityExtensions - { - /// - /// Registers an object for navigation - /// - /// - /// The type of object to register - /// The unique name to register with the obect. - /// - public static IUnityContainer RegisterTypeForNavigation(this IUnityContainer container, Type type, string name) - { - return container.RegisterType(typeof(object), type, name); - } - - /// - /// Registers an object for navigation. - /// - /// The Type of the object to register as the view - /// - /// The unique name to register with the object. - public static IUnityContainer RegisterTypeForNavigation(this IUnityContainer container, string name = null) - { - Type type = typeof(T); - string viewName = string.IsNullOrWhiteSpace(name) ? type.Name : name; - return container.RegisterTypeForNavigation(type, viewName); - } - - /// - /// Registers an object for navigation. - /// - /// The Type of object to register as the view - /// The ViewModel to use as the DataContext for the view - /// The unique name to register with the view - /// - public static IUnityContainer RegisterTypeForNavigation(this IUnityContainer container, string name = null) - { - return container.RegisterTypeForNavigationWithViewModel(typeof(TView), name); - } - - private static IUnityContainer RegisterTypeForNavigationWithViewModel(this IUnityContainer container, Type viewType, string name) - { - if (string.IsNullOrWhiteSpace(name)) - name = viewType.Name; - - ViewModelLocationProvider.Register(viewType.ToString(), typeof(TViewModel)); - - return container.RegisterTypeForNavigation(viewType, name); - } - } -} diff --git a/src/Wpf/Prism.Unity.Wpf/Properties/Resources.Designer.cs b/src/Wpf/Prism.Unity.Wpf/Properties/Resources.Designer.cs index 5e49372e39..9d45060f5c 100644 --- a/src/Wpf/Prism.Unity.Wpf/Properties/Resources.Designer.cs +++ b/src/Wpf/Prism.Unity.Wpf/Properties/Resources.Designer.cs @@ -60,123 +60,6 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to Bootstrapper sequence completed.. - /// - internal static string BootstrapperSequenceCompleted { - get { - return ResourceManager.GetString("BootstrapperSequenceCompleted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring the Unity container.. - /// - internal static string ConfiguringContainer { - get { - return ResourceManager.GetString("ConfiguringContainer", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring default region behaviors.. - /// - internal static string ConfiguringDefaultRegionBehaviors { - get { - return ResourceManager.GetString("ConfiguringDefaultRegionBehaviors", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring module catalog.. - /// - internal static string ConfiguringModuleCatalog { - get { - return ResourceManager.GetString("ConfiguringModuleCatalog", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring region adapters.. - /// - internal static string ConfiguringRegionAdapters { - get { - return ResourceManager.GetString("ConfiguringRegionAdapters", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring ServiceLocator singleton.. - /// - internal static string ConfiguringServiceLocatorSingleton { - get { - return ResourceManager.GetString("ConfiguringServiceLocatorSingleton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Configuring the ViewModelLocator to use Unity.. - /// - internal static string ConfiguringViewModelLocator { - get { - return ResourceManager.GetString("ConfiguringViewModelLocator", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating Unity container.. - /// - internal static string CreatingContainer { - get { - return ResourceManager.GetString("CreatingContainer", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating module catalog.. - /// - internal static string CreatingModuleCatalog { - get { - return ResourceManager.GetString("CreatingModuleCatalog", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Creating the shell.. - /// - internal static string CreatingShell { - get { - return ResourceManager.GetString("CreatingShell", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Initializing modules.. - /// - internal static string InitializingModules { - get { - return ResourceManager.GetString("InitializingModules", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Initializing the shell.. - /// - internal static string InitializingShell { - get { - return ResourceManager.GetString("InitializingShell", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Logger was created successfully.. - /// - internal static string LoggerCreatedSuccessfully { - get { - return ResourceManager.GetString("LoggerCreatedSuccessfully", resourceCulture); - } - } - /// /// Looks up a localized string similar to The method 'GetModuleEnumerator' of the bootstrapper must be overwritten in order to use the default module initialization logic.. /// @@ -213,15 +96,6 @@ internal static string NullUnityContainerException { } } - /// - /// Looks up a localized string similar to Registering Framework Exception Types.. - /// - internal static string RegisteringFrameworkExceptionTypes { - get { - return ResourceManager.GetString("RegisteringFrameworkExceptionTypes", resourceCulture); - } - } - /// /// Looks up a localized string similar to Setting the RegionManager.. /// @@ -239,14 +113,5 @@ internal static string TypeMappingAlreadyRegistered { return ResourceManager.GetString("TypeMappingAlreadyRegistered", resourceCulture); } } - - /// - /// Looks up a localized string similar to Updating Regions.. - /// - internal static string UpdatingRegions { - get { - return ResourceManager.GetString("UpdatingRegions", resourceCulture); - } - } } } diff --git a/src/Wpf/Prism.Unity.Wpf/Properties/Resources.resx b/src/Wpf/Prism.Unity.Wpf/Properties/Resources.resx index 3463ff1cea..8a1e801d4f 100644 --- a/src/Wpf/Prism.Unity.Wpf/Properties/Resources.resx +++ b/src/Wpf/Prism.Unity.Wpf/Properties/Resources.resx @@ -117,45 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Bootstrapper sequence completed. - - - Configuring the Unity container. - - - Configuring default region behaviors. - - - Configuring module catalog. - - - Configuring region adapters. - - - Configuring ServiceLocator singleton. - - - Configuring the ViewModelLocator to use Unity. - - - Creating Unity container. - - - Creating module catalog. - - - Creating the shell. - - - Initializing modules. - - - Initializing the shell. - - - Logger was created successfully. - The method 'GetModuleEnumerator' of the bootstrapper must be overwritten in order to use the default module initialization logic. @@ -168,16 +129,10 @@ The IUnityContainer is required and cannot be null. - - Registering Framework Exception Types. - Setting the RegionManager. Type '{0}' was already registered by the application. Skipping... - - Updating Regions. - \ No newline at end of file diff --git a/src/Wpf/Prism.Wpf/Bootstrapper.cs b/src/Wpf/Prism.Wpf/Bootstrapper.cs deleted file mode 100644 index ab6ab63733..0000000000 --- a/src/Wpf/Prism.Wpf/Bootstrapper.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using Prism.Ioc; -using Prism.Modularity; -using Prism.Mvvm; -using Prism.Regions; -using Prism.Regions.Behaviors; - -namespace Prism -{ - /// - /// Base class that provides a basic bootstrapping sequence and hooks - /// that specific implementations can override - /// - /// - /// This class must be overridden to provide application specific configuration. - /// - [Obsolete("This class will be removed in Prism 8.1. Please migrate to the PrismApplication or the new PrismBootstrapper.")] - public abstract class Bootstrapper - { - /// - /// Gets the for the application. - /// - /// A instance. - protected IContainerExtension ContainerExtension; - - /// - /// Gets the default for the application. - /// - /// The default instance. - protected IModuleCatalog ModuleCatalog { get; set; } - - /// - /// Gets the shell user interface - /// - /// The shell user interface. - protected DependencyObject Shell { get; set; } - - /// - /// Creates the container extension used by Prism. - /// - /// The container extension. - protected abstract IContainerExtension CreateContainerExtension(); - - /// - /// Runs the bootstrapper process. - /// - public void Run() - { - this.Run(true); - - this.OnInitialized(); - } - - protected virtual void Log(string message) - { - // Intentionally left blank - } - - /// - /// Creates the used by Prism. - /// - /// - /// The base implementation returns a new ModuleCatalog. - /// - protected virtual IModuleCatalog CreateModuleCatalog() - { - return new ModuleCatalog(); - } - - /// - /// Configures the used by Prism. - /// - protected virtual void ConfigureModuleCatalog() - { - } - - /// - /// Configures the used by Prism. - /// - protected virtual void ConfigureViewModelLocator() - { - ViewModelLocationProvider.SetDefaultViewModelFactory((type) => ContainerLocator.Container.Resolve(type)); - } - - /// - /// Registers the s of the Exceptions that are not considered - /// root exceptions by the . - /// - protected virtual void RegisterFrameworkExceptionTypes() - { - } - - /// - /// Initializes the modules. May be overwritten in a derived class to use a custom Modules Catalog - /// - protected virtual void InitializeModules() - { - IModuleManager manager = ContainerLocator.Container.Resolve(); - manager.Run(); - } - - /// - /// 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 RegionAdapterMappings ConfigureRegionAdapterMappings() - { - var container = ContainerLocator.Container; - RegionAdapterMappings regionAdapterMappings = container.Resolve(); - if (regionAdapterMappings != null) - { - regionAdapterMappings.RegisterMapping(typeof(Selector), container.Resolve()); - regionAdapterMappings.RegisterMapping(typeof(ItemsControl), container.Resolve()); - regionAdapterMappings.RegisterMapping(typeof(ContentControl), container.Resolve()); - } - - return regionAdapterMappings; - } - - /// - /// Configures the . - /// This will be the list of default behaviors that will be added to a region. - /// - protected virtual IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() - { - var defaultRegionBehaviorTypesDictionary = ContainerLocator.Container.Resolve(); - - if (defaultRegionBehaviorTypesDictionary != null) - { - defaultRegionBehaviorTypesDictionary.AddIfMissing(BindRegionContextToDependencyObjectBehavior.BehaviorKey, - typeof(BindRegionContextToDependencyObjectBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionActiveAwareBehavior.BehaviorKey, - typeof(RegionActiveAwareBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(SyncRegionContextWithHostBehavior.BehaviorKey, - typeof(SyncRegionContextWithHostBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionManagerRegistrationBehavior.BehaviorKey, - typeof(RegionManagerRegistrationBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionMemberLifetimeBehavior.BehaviorKey, - typeof(RegionMemberLifetimeBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(ClearChildViewsRegionBehavior.BehaviorKey, - typeof(ClearChildViewsRegionBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey, - typeof(AutoPopulateRegionBehavior)); - - defaultRegionBehaviorTypesDictionary.AddIfMissing(DestructibleRegionBehavior.BehaviorKey, typeof(DestructibleRegionBehavior)); - } - - return defaultRegionBehaviorTypesDictionary; - } - - /// - /// Creates the shell or main window of the application. - /// - /// The shell of the application. - /// - /// If the returned instance is a , the - /// will attach the default of - /// the application in its attached property - /// in order to be able to add regions by using the - /// attached property from XAML. - /// - protected virtual DependencyObject CreateShell() - { - return null; - } - - /// - /// Initializes the shell. - /// - protected virtual void InitializeShell() - { - } - - /// - /// Run the bootstrapper process. - /// - /// If , registers default - /// Prism Library services in the container. This is the default behavior. - public abstract void Run(bool runWithDefaultConfiguration); - - /// - /// Contains actions that should occur last. - /// - protected virtual void OnInitialized() - { - } - } -} diff --git a/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs index 1d966ae349..8d1149db29 100644 --- a/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs +++ b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs @@ -28,7 +28,7 @@ public abstract class PrismBootstrapperBase /// Gets the shell user interface /// /// The shell user interface. - protected Window Shell { get; set; } + protected DependencyObject Shell { get; set; } /// /// Runs the bootstrapper process. @@ -105,6 +105,9 @@ protected virtual IModuleCatalog CreateModuleCatalog() /// protected virtual void RegisterRequiredTypes(IContainerRegistry containerRegistry) { + if (_moduleCatalog == null) + throw new InvalidOperationException("IModuleCatalog"); + containerRegistry.RegisterRequiredTypes(_moduleCatalog); } @@ -145,12 +148,12 @@ protected virtual void RegisterFrameworkExceptionTypes() /// Creates the shell or main window of the application. /// /// The shell of the application. - protected abstract Window CreateShell(); + protected abstract DependencyObject CreateShell(); /// /// Initializes the shell. /// - protected virtual void InitializeShell(Window shell) + protected virtual void InitializeShell(DependencyObject shell) { Shell = shell; } @@ -160,7 +163,8 @@ protected virtual void InitializeShell(Window shell) /// protected virtual void OnInitialized() { - Shell?.Show(); + if (Shell is Window window) + window.Show(); } /// diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperNullModuleManagerFixture.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperNullModuleManagerFixture.cs deleted file mode 100644 index 3e1375928d..0000000000 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperNullModuleManagerFixture.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Prism.Container.Wpf.Mocks; -using Xunit; - -namespace Prism.Container.Wpf.Tests.Bootstrapper -{ - [Collection(nameof(ContainerExtension))] - public class BootstrapperNullModuleManagerFixture - { - [Fact] - public void RunShouldNotCallInitializeModulesWhenModuleManagerNotFound() - { - var bootstrapper = new NullModuleManagerBootstrapper(); - - bootstrapper.Run(); - - Assert.False(bootstrapper.InitializeModulesCalled); - } - } -} diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs index 5b88bbb94b..5abd489594 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs @@ -131,13 +131,23 @@ public void RunShouldCallCreateShell() } [StaFact] - public void RunShouldCallConfigureContainer() + public void RunShouldCallRegisterRequiredTypes() { var bootstrapper = new MockBootstrapper(); bootstrapper.Run(); - Assert.True(bootstrapper.ConfigureContainerCalled); + Assert.True(bootstrapper.RegisterRequiredTypesCalled); + } + + [StaFact] + public void RunShouldCallRegisterTypes() + { + var bootstrapper = new MockBootstrapper(); + + bootstrapper.Run(); + + Assert.True(bootstrapper.RegisterTypesCalled); } [StaFact] @@ -150,7 +160,7 @@ public void SetsContainerLocatorCurrentContainer() bootstrapper.Run(); Assert.NotNull(ContainerLocator.Container); - Assert.Same(bootstrapper.Container, ContainerLocator.Container.GetBaseContainer()); + Assert.Same(bootstrapper.Container, ContainerLocator.Container); } [StaFact] @@ -206,182 +216,19 @@ public void RunShouldCallTheMethodsInOrder() bootstrapper.Run(); var index = 0; - Assert.Equal("CreateModuleCatalog", bootstrapper.MethodCalls[index++]); - Assert.Equal("ConfigureModuleCatalog", bootstrapper.MethodCalls[index++]); - Assert.Equal("CreateContainer", bootstrapper.MethodCalls[index++]); - Assert.Equal("ConfigureContainer", bootstrapper.MethodCalls[index++]); Assert.Equal("ConfigureViewModelLocator", bootstrapper.MethodCalls[index++]); + Assert.Equal("CreateContainerExtension", bootstrapper.MethodCalls[index++]); + Assert.Equal("CreateModuleCatalog", bootstrapper.MethodCalls[index++]); + Assert.Equal("RegisterRequiredTypes", bootstrapper.MethodCalls[index++]); + Assert.Equal("RegisterTypes", bootstrapper.MethodCalls[index++]); + Assert.Equal("ConfigureModuleCatalog", bootstrapper.MethodCalls[index++]); Assert.Equal("ConfigureRegionAdapterMappings", bootstrapper.MethodCalls[index++]); Assert.Equal("ConfigureDefaultRegionBehaviors", bootstrapper.MethodCalls[index++]); Assert.Equal("RegisterFrameworkExceptionTypes", bootstrapper.MethodCalls[index++]); Assert.Equal("CreateShell", bootstrapper.MethodCalls[index++]); Assert.Equal("InitializeShell", bootstrapper.MethodCalls[index++]); Assert.Equal("InitializeModules", bootstrapper.MethodCalls[index++]); - } - - [StaFact] - public void RunShouldLogBootstrapperSteps() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - var index = 0; - Assert.Contains(ContainerResources.LoggerCreatedSuccessfully, messages[index++]); - Assert.Contains(ContainerResources.CreatingModuleCatalog, messages[index++]); - Assert.Contains(ContainerResources.ConfiguringModuleCatalog, messages[index++]); - Assert.Contains(ContainerResources.CreatingContainer, messages[index++]); - Assert.Contains(ContainerResources.ConfiguringContainer, messages[index++]); - Assert.Contains(ContainerResources.ConfiguringViewModelLocator, messages[index++]); - Assert.Contains(ContainerResources.ConfiguringRegionAdapters, messages[index++]); - Assert.Contains(ContainerResources.ConfiguringDefaultRegionBehaviors, messages[index++]); - Assert.Contains(ContainerResources.RegisteringFrameworkExceptionTypes, messages[index++]); - Assert.Contains(ContainerResources.CreatingShell, messages[index++]); - Assert.Contains(ContainerResources.SettingTheRegionManager, messages[index++]); - Assert.Contains(ContainerResources.UpdatingRegions, messages[index++]); - Assert.Contains(ContainerResources.InitializingShell, messages[index++]); - Assert.Contains(ContainerResources.InitializingModules, messages[index++]); - Assert.Contains(ContainerResources.BootstrapperSequenceCompleted, messages[index++]); - } - - [StaFact] - public void RunShouldLogLoggerCreationSuccess() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.LoggerCreatedSuccessfully, messages); - } - [StaFact] - public void RunShouldLogAboutModuleCatalogCreation() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - Assert.Contains(ContainerResources.CreatingModuleCatalog, messages); - } - - [StaFact] - public void RunShouldLogAboutConfiguringModuleCatalog() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.ConfiguringModuleCatalog, messages); - } - - [StaFact] - public void RunShouldLogAboutCreatingTheContainer() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.CreatingContainer, messages); - } - - [StaFact] - public void RunShouldLogAboutConfiguringContainer() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.ConfiguringContainer, messages); - } - - [StaFact] - public void RunShouldLogAboutConfiguringViewModelLocator() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.ConfiguringViewModelLocator, messages); - } - - [StaFact] - public void RunShouldLogAboutConfiguringRegionAdapters() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.ConfiguringRegionAdapters, messages); - } - - [StaFact] - public void RunShouldLogAboutConfiguringRegionBehaviors() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.ConfiguringDefaultRegionBehaviors, messages); - } - - [StaFact] - public void RunShouldLogAboutRegisteringFrameworkExceptionTypes() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.RegisteringFrameworkExceptionTypes, messages); - } - - [StaFact] - public void RunShouldLogAboutCreatingTheShell() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.CreatingShell, messages); - } - - [StaFact] - public void RunShouldLogAboutInitializingTheShellIfShellCreated() - { - var bootstrapper = new MockBootstrapper(); - - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.InitializingShell, messages); - } - - [StaFact] - public void RunShouldNotLogAboutInitializingTheShellIfShellIsNotCreated() - { - var bootstrapper = new MockBootstrapper { ShellObject = null }; - - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.DoesNotContain(ContainerResources.InitializingShell, messages); - } - - [StaFact] - public void RunShouldLogAboutInitializingModules() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.InitializingModules, messages); - } - - [StaFact] - public void RunShouldLogAboutRunCompleting() - { - var bootstrapper = new MockBootstrapper(); - bootstrapper.Run(); - var messages = bootstrapper.Messages; - - Assert.Contains(ContainerResources.BootstrapperSequenceCompleted, messages); + Assert.Equal("OnInitialized", bootstrapper.MethodCalls[index++]); } } } diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleCatalogBootstrapper.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleCatalogBootstrapper.cs index c323d54cc9..d5be382d99 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleCatalogBootstrapper.cs +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleCatalogBootstrapper.cs @@ -1,6 +1,6 @@ -using System; -using System.Windows; +using Prism.Ioc; using Prism.Modularity; +using System.Windows; namespace Prism.Container.Wpf.Mocks { @@ -13,12 +13,12 @@ protected override IModuleCatalog CreateModuleCatalog() protected override DependencyObject CreateShell() { - throw new NotImplementedException(); + return null; } - protected override void InitializeShell() + protected override void RegisterTypes(IContainerRegistry containerRegistry) { - throw new NotImplementedException(); + } } } diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleManagerBootstrapper.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleManagerBootstrapper.cs deleted file mode 100644 index 74ff67e571..0000000000 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Mocks/NullModuleManagerBootstrapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Windows; -using Prism.Ioc; -using Prism.Regions; - -namespace Prism.Container.Wpf.Mocks -{ - internal partial class NullModuleManagerBootstrapper - { - public bool InitializeModulesCalled; - - protected override void ConfigureContainer() - { - //base.RegisterDefaultTypesIfMissing(); - - ContainerExtension.RegisterInstance(ModuleCatalog); - } - - protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() - { - return null; - } - - protected override RegionAdapterMappings ConfigureRegionAdapterMappings() - { - return null; - } - - protected override DependencyObject CreateShell() - { - return null; - } - - protected override void InitializeModules() - { - this.InitializeModulesCalled = true; - } - } -} diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Prism.Container.Wpf.Shared.projitems b/tests/Wpf/Prism.Container.Wpf.Shared/Prism.Container.Wpf.Shared.projitems index 68e34ac7f4..86e2cb6513 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Prism.Container.Wpf.Shared.projitems +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Prism.Container.Wpf.Shared.projitems @@ -13,12 +13,10 @@ - - diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs index 7b2fc13ef1..56a0e37a20 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs @@ -1,13 +1,13 @@ -using System; +using System; +using DryIoc; using Moq; using Prism.Container.Wpf.Mocks; +using Prism.DryIoc; using Prism.Events; using Prism.Ioc; using Prism.Modularity; using Prism.Regions; -using Prism.DryIoc; using Xunit; -using DryIoc; namespace Prism.Container.Wpf.Tests.Bootstrapper { @@ -34,7 +34,7 @@ public void RunRegistersInstanceOfIModuleCatalog() bootstrapper.Run(); - mockedContainer.Verify(c => c.UseInstance(typeof(IModuleCatalog), It.IsAny(), IfAlreadyRegistered.Replace, It.IsAny(), It.IsAny(), It.IsAny())); + mockedContainer.Verify(c => c.Register(It.IsAny(), typeof(IModuleCatalog), It.IsAny(), It.IsAny(), It.IsAny())); } [StaFact] @@ -141,25 +141,26 @@ private static void SetupMockedContainerForVerificationTests(Mock mo mockedContainer.Setup(c => c.Register(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); - mockedContainer.Setup(c => c.Resolve(typeof(IModuleCatalog), IfUnresolved.Throw)).Returns( + // NOTE: The actual method called by Prism's DryIocContainerExtension is off over the IResolver not IContainer + mockedContainer.As().Setup(r => r.Resolve(typeof(IModuleCatalog), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( new ModuleCatalog()); - mockedContainer.Setup(c => c.Resolve(typeof(IModuleInitializer), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(IModuleInitializer), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( mockedModuleInitializer.Object); - mockedContainer.Setup(c => c.Resolve(typeof(IModuleManager), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(IModuleManager), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( mockedModuleManager.Object); - mockedContainer.Setup(c => c.Resolve(typeof(RegionAdapterMappings), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(RegionAdapterMappings), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( regionAdapterMappings); - mockedContainer.Setup(c => c.Resolve(typeof(SelectorRegionAdapter), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(SelectorRegionAdapter), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( new SelectorRegionAdapter(regionBehaviorFactory)); - mockedContainer.Setup(c => c.Resolve(typeof(ItemsControlRegionAdapter), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(ItemsControlRegionAdapter), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( new ItemsControlRegionAdapter(regionBehaviorFactory)); - mockedContainer.Setup(c => c.Resolve(typeof(ContentControlRegionAdapter), IfUnresolved.Throw)).Returns( + mockedContainer.As().Setup(c => c.Resolve(typeof(ContentControlRegionAdapter), It.IsAny(), IfUnresolved.Throw, It.IsAny(), It.IsAny(), It.IsAny())).Returns( new ContentControlRegionAdapter(regionBehaviorFactory)); } } diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs index f5afa3f47e..d2defd122e 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs @@ -5,70 +5,77 @@ using DryIoc; using Prism.DryIoc; using Prism.Ioc; -using Prism.IocContainer.Wpf.Tests.Support.Mocks; using Prism.Modularity; using Prism.Regions; namespace Prism.Container.Wpf.Mocks { - internal class MockBootstrapper : DryIocBootstrapper + internal class MockBootstrapper : PrismBootstrapper { public List MethodCalls = new List(); public bool InitializeModulesCalled; public bool ConfigureRegionAdapterMappingsCalled; public RegionAdapterMappings DefaultRegionAdapterMappings; public bool CreateModuleCatalogCalled; - public bool ConfigureContainerCalled; + public bool RegisterRequiredTypesCalled; + public bool RegisterTypesCalled; public bool CreateShellCalled; public bool CreateContainerCalled; public bool ConfigureModuleCatalogCalled; public bool InitializeShellCalled; + public bool OnInitializeCalled; public bool ConfigureViewModelLocatorCalled; public bool ConfigureDefaultRegionBehaviorsCalled; - public DependencyObject ShellObject = new UserControl(); + public UserControl ShellObject = new UserControl(); public DependencyObject BaseShell => base.Shell; public IContainer BaseContainer { - get => base.Container; - set => base.Container = value; + get => base.Container?.GetContainer(); } - public override void Run(bool runWithDefaultConfiguration) - { - ContainerLocator.ResetContainer(); - base.Run(runWithDefaultConfiguration); - } - - public new IContainerExtension ContainerExtension => base.ContainerExtension; + public IContainerExtension ContainerExtension => (IContainerExtension)base.Container; - public IContainerRegistry ContainerRegistry => base.ContainerExtension; + public IContainerRegistry ContainerRegistry => (IContainerRegistry)base.Container; public IContainer CallCreateContainer() { - return this.CreateContainer(); + var containerExt = this.CreateContainerExtension(); + return ((IContainerExtension)containerExt).Instance; } - protected override IContainer CreateContainer() + protected override DependencyObject CreateShell() { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.CreateContainerCalled = true; - return base.CreateContainer(); + this.CreateShellCalled = true; + return ShellObject; } - protected override void ConfigureContainer() + protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.ConfigureContainerCalled = true; - base.ConfigureContainer(); + this.RegisterRequiredTypesCalled = true; + base.RegisterRequiredTypes(containerRegistry); } - protected override DependencyObject CreateShell() + protected override void RegisterTypes(IContainerRegistry containerRegistry) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.CreateShellCalled = true; - return ShellObject; + this.RegisterTypesCalled = true; + } + + protected override void Initialize() + { + ContainerLocator.ResetContainer(); + base.Initialize(); + } + + protected override IContainerExtension CreateContainerExtension() + { + this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); + this.CreateContainerCalled = true; + return base.CreateContainerExtension(); } protected override void ConfigureViewModelLocator() @@ -85,18 +92,25 @@ protected override IModuleCatalog CreateModuleCatalog() return base.CreateModuleCatalog(); } - protected override void ConfigureModuleCatalog() + protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.ConfigureModuleCatalogCalled = true; - base.ConfigureModuleCatalog(); + base.ConfigureModuleCatalog(moduleCatalog); } - protected override void InitializeShell() + protected override void InitializeShell(DependencyObject shell) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.InitializeShellCalled = true; - // no op + base.InitializeShell(shell); + } + + protected override void OnInitialized() + { + this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); + this.OnInitializeCalled = true; + base.OnInitialized(); } protected override void InitializeModules() @@ -106,22 +120,21 @@ protected override void InitializeModules() base.InitializeModules(); } - protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() + protected override void ConfigureDefaultRegionBehaviors(IRegionBehaviorFactory regionBehaviors) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.ConfigureDefaultRegionBehaviorsCalled = true; - return base.ConfigureDefaultRegionBehaviors(); + base.ConfigureDefaultRegionBehaviors(regionBehaviors); } - protected override RegionAdapterMappings ConfigureRegionAdapterMappings() + protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); ConfigureRegionAdapterMappingsCalled = true; - var regionAdapterMappings = base.ConfigureRegionAdapterMappings(); - DefaultRegionAdapterMappings = regionAdapterMappings; + base.ConfigureRegionAdapterMappings(regionAdapterMappings); - return regionAdapterMappings; + DefaultRegionAdapterMappings = regionAdapterMappings; } protected override void RegisterFrameworkExceptionTypes() @@ -134,12 +147,5 @@ public void CallRegisterFrameworkExceptionTypes() { base.RegisterFrameworkExceptionTypes(); } - - public List Messages { get; } = new List(); - - protected override void Log(string message) - { - Messages.Add(message); - } } } diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs index 2e3d0e8159..2c0ffb6855 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs @@ -6,24 +6,28 @@ namespace Prism.Container.Wpf.Mocks { - internal class MockedContainerBootstrapper : DryIocBootstrapper + internal class MockedContainerBootstrapper : PrismBootstrapper { - private readonly IContainer container; + private readonly IContainer _container; - public void CallConfigureContainer() + public MockedContainerBootstrapper(IContainer container) { - base.ConfigureContainer(); + ContainerLocator.ResetContainer(); + this._container = container; } - public MockedContainerBootstrapper(IContainer container) + bool _useDefaultConfiguration = true; + + public void Run(bool useDefaultConfiguration) { - ContainerLocator.ResetContainer(); - this.container = container; + _useDefaultConfiguration = useDefaultConfiguration; + + base.Run(); } - protected override IContainer CreateContainer() + protected override IContainerExtension CreateContainerExtension() { - return container; + return new DryIocContainerExtension(_container); } protected override DependencyObject CreateShell() @@ -31,9 +35,20 @@ protected override DependencyObject CreateShell() return new UserControl(); } - protected override void InitializeShell() + protected override void InitializeShell(DependencyObject shell) + { + + } + + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + + } + + protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry) { - // no op + if (_useDefaultConfiguration) + base.RegisterRequiredTypes(containerRegistry); } } } diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullContainerBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullContainerBootstrapper.cs deleted file mode 100644 index 3a742b15e5..0000000000 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullContainerBootstrapper.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Windows; -using DryIoc; -using Prism.DryIoc; - -namespace Prism.Container.Wpf.Mocks -{ - internal class NullContainerBootstrapper : DryIocBootstrapper - { - protected override IContainer CreateContainer() - { - return null; - } - protected override DependencyObject CreateShell() - { - throw new NotImplementedException(); - } - - protected override void InitializeShell() - { - throw new NotImplementedException(); - } - } -} diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs index 53161ab126..0976ee400d 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs @@ -1,8 +1,19 @@ using Prism.DryIoc; +using Prism.Ioc; +using System.Windows; namespace Prism.Container.Wpf.Mocks { - internal partial class NullLoggerBootstrapper : DryIocBootstrapper + internal partial class NullLoggerBootstrapper : PrismBootstrapper { + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + throw new System.NotImplementedException(); + } + + protected override DependencyObject CreateShell() + { + throw new System.NotImplementedException(); + } } } diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs index d2dfaf88d0..a96a9aa21c 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs @@ -2,7 +2,7 @@ namespace Prism.Container.Wpf.Mocks { - internal partial class NullModuleCatalogBootstrapper : DryIocBootstrapper + internal partial class NullModuleCatalogBootstrapper : PrismBootstrapper { } } diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs deleted file mode 100644 index 7a770036a6..0000000000 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.DryIoc; - -namespace Prism.Container.Wpf.Mocks -{ - internal partial class NullModuleManagerBootstrapper : DryIocBootstrapper - { - } -} diff --git a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/BootstrapperFixtureBase.cs b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/BootstrapperFixtureBase.cs index b919e11078..04bf49ee41 100644 --- a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/BootstrapperFixtureBase.cs +++ b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/BootstrapperFixtureBase.cs @@ -1,4 +1,3 @@ - using System; using Xunit; @@ -6,7 +5,7 @@ namespace Prism.IocContainer.Wpf.Tests.Support { public class BootstrapperFixtureBase { - protected static void AssertExceptionThrownOnRun(Bootstrapper bootstrapper, Type expectedExceptionType, string expectedExceptionMessageSubstring) + protected static void AssertExceptionThrownOnRun(PrismBootstrapperBase bootstrapper, Type expectedExceptionType, string expectedExceptionMessageSubstring) { bool exceptionThrown = false; try diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperNullContainerFixture.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperNullContainerFixture.cs deleted file mode 100644 index 10e26e50d2..0000000000 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperNullContainerFixture.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Prism.Container.Wpf.Mocks; -using Prism.IocContainer.Wpf.Tests.Support; -using Xunit; - -namespace Prism.Container.Wpf.Tests.Bootstrapper -{ - public class BootstrapperNullContainerFixture : BootstrapperFixtureBase - { - [Fact] - public void RunThrowsWhenNullContainerCreated() - { - var bootstrapper = new NullContainerBootstrapper(); - - AssertExceptionThrownOnRun(bootstrapper, typeof(InvalidOperationException), "IUnityContainer"); - } - } -} \ No newline at end of file diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs index 7c4fd2dc96..6d9ce72ffb 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs @@ -10,65 +10,72 @@ namespace Prism.Container.Wpf.Mocks { - internal class MockBootstrapper : UnityBootstrapper + internal class MockBootstrapper : PrismBootstrapper { public List MethodCalls = new List(); public bool InitializeModulesCalled; public bool ConfigureRegionAdapterMappingsCalled; public RegionAdapterMappings DefaultRegionAdapterMappings; - public bool CreateLoggerCalled; public bool CreateModuleCatalogCalled; - public bool ConfigureContainerCalled; + public bool RegisterRequiredTypesCalled; + public bool RegisterTypesCalled; public bool CreateShellCalled; public bool CreateContainerCalled; public bool ConfigureModuleCatalogCalled; public bool InitializeShellCalled; + public bool OnInitializeCalled; public bool ConfigureViewModelLocatorCalled; public bool ConfigureDefaultRegionBehaviorsCalled; - public DependencyObject ShellObject = new UserControl(); + public UserControl ShellObject = new UserControl(); public DependencyObject BaseShell => base.Shell; public IUnityContainer BaseContainer { - get => base.Container; - set => base.Container = value; + get => base.Container?.GetContainer(); } - public override void Run(bool runWithDefaultConfiguration) - { - ContainerLocator.ResetContainer(); - base.Run(runWithDefaultConfiguration); - } - - public new IContainerExtension ContainerExtension => base.ContainerExtension; + public IContainerExtension ContainerExtension => (IContainerExtension)base.Container; - public IContainerRegistry ContainerRegistry => base.ContainerExtension; + public IContainerRegistry ContainerRegistry => (IContainerRegistry)base.Container; public IUnityContainer CallCreateContainer() { - return this.CreateContainer(); + var containerExt = this.CreateContainerExtension(); + return ((IContainerExtension)containerExt).Instance; } - protected override IUnityContainer CreateContainer() + protected override DependencyObject CreateShell() { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.CreateContainerCalled = true; - return base.CreateContainer(); + this.CreateShellCalled = true; + return ShellObject; } - protected override void ConfigureContainer() + protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.ConfigureContainerCalled = true; - base.ConfigureContainer(); + this.RegisterRequiredTypesCalled = true; + base.RegisterRequiredTypes(containerRegistry); } - protected override DependencyObject CreateShell() + protected override void RegisterTypes(IContainerRegistry containerRegistry) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); - this.CreateShellCalled = true; - return ShellObject; + this.RegisterTypesCalled = true; + } + + protected override void Initialize() + { + ContainerLocator.ResetContainer(); + base.Initialize(); + } + + protected override IContainerExtension CreateContainerExtension() + { + this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); + this.CreateContainerCalled = true; + return base.CreateContainerExtension(); } protected override void ConfigureViewModelLocator() @@ -85,18 +92,25 @@ protected override IModuleCatalog CreateModuleCatalog() return base.CreateModuleCatalog(); } - protected override void ConfigureModuleCatalog() + protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.ConfigureModuleCatalogCalled = true; - base.ConfigureModuleCatalog(); + base.ConfigureModuleCatalog(moduleCatalog); } - protected override void InitializeShell() + protected override void InitializeShell(DependencyObject shell) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.InitializeShellCalled = true; - // no op + base.InitializeShell(shell); + } + + protected override void OnInitialized() + { + this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); + this.OnInitializeCalled = true; + base.OnInitialized(); } protected override void InitializeModules() @@ -106,22 +120,21 @@ protected override void InitializeModules() base.InitializeModules(); } - protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() + protected override void ConfigureDefaultRegionBehaviors(IRegionBehaviorFactory regionBehaviors) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); this.ConfigureDefaultRegionBehaviorsCalled = true; - return base.ConfigureDefaultRegionBehaviors(); + base.ConfigureDefaultRegionBehaviors(regionBehaviors); } - protected override RegionAdapterMappings ConfigureRegionAdapterMappings() + protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); ConfigureRegionAdapterMappingsCalled = true; - var regionAdapterMappings = base.ConfigureRegionAdapterMappings(); - DefaultRegionAdapterMappings = regionAdapterMappings; + base.ConfigureRegionAdapterMappings(regionAdapterMappings); - return regionAdapterMappings; + DefaultRegionAdapterMappings = regionAdapterMappings; } protected override void RegisterFrameworkExceptionTypes() @@ -134,12 +147,5 @@ public void CallRegisterFrameworkExceptionTypes() { base.RegisterFrameworkExceptionTypes(); } - - public List Messages { get; } = new List(); - - protected override void Log(string message) - { - Messages.Add(message); - } } } diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs index d2670f95ce..e14ad5a3eb 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs @@ -6,24 +6,28 @@ namespace Prism.Container.Wpf.Mocks { - internal class MockedContainerBootstrapper : UnityBootstrapper + internal class MockedContainerBootstrapper : PrismBootstrapper { - private readonly IUnityContainer container; + private readonly IUnityContainer _container; - public void CallConfigureContainer() + public MockedContainerBootstrapper(IUnityContainer container) { - base.ConfigureContainer(); + ContainerLocator.ResetContainer(); + this._container = container; } - public MockedContainerBootstrapper(IUnityContainer container) + bool _useDefaultConfiguration = true; + + public void Run(bool useDefaultConfiguration) { - ContainerLocator.ResetContainer(); - this.container = container; + _useDefaultConfiguration = useDefaultConfiguration; + + base.Run(); } - protected override IUnityContainer CreateContainer() + protected override IContainerExtension CreateContainerExtension() { - return container; + return new UnityContainerExtension(_container); } protected override DependencyObject CreateShell() @@ -31,9 +35,20 @@ protected override DependencyObject CreateShell() return new UserControl(); } - protected override void InitializeShell() + protected override void InitializeShell(DependencyObject shell) + { + + } + + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + + } + + protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry) { - // no op + if (_useDefaultConfiguration) + base.RegisterRequiredTypes(containerRegistry); } } } diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullContainerBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullContainerBootstrapper.cs deleted file mode 100644 index c8d55284e4..0000000000 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullContainerBootstrapper.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Windows; -using Prism.Unity; -using Unity; - -namespace Prism.Container.Wpf.Mocks -{ - internal class NullContainerBootstrapper : UnityBootstrapper - { - protected override IUnityContainer CreateContainer() - { - return null; - } - protected override DependencyObject CreateShell() - { - throw new NotImplementedException(); - } - - protected override void InitializeShell() - { - throw new NotImplementedException(); - } - } -} diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs index 09700c5d17..e8159ddc81 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullLoggerBootstrapper.cs @@ -1,8 +1,19 @@ -using Prism.Unity; +using Prism.Ioc; +using Prism.Unity; +using System.Windows; namespace Prism.Container.Wpf.Mocks { - internal partial class NullLoggerBootstrapper : UnityBootstrapper + internal partial class NullLoggerBootstrapper : PrismBootstrapper { + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + throw new System.NotImplementedException(); + } + + protected override DependencyObject CreateShell() + { + throw new System.NotImplementedException(); + } } } diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs index bff1ad004b..c91acf0cd9 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleCatalogBootstrapper.cs @@ -2,7 +2,7 @@ namespace Prism.Container.Wpf.Mocks { - internal partial class NullModuleCatalogBootstrapper : UnityBootstrapper + internal partial class NullModuleCatalogBootstrapper : PrismBootstrapper { } } diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs deleted file mode 100644 index 885bd662a2..0000000000 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/NullModuleManagerBootstrapper.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Unity; - -namespace Prism.Container.Wpf.Mocks -{ - internal partial class NullModuleManagerBootstrapper : UnityBootstrapper - { - } -} diff --git a/tests/Wpf/Prism.Wpf.Tests/BootstrapperFixture.cs b/tests/Wpf/Prism.Wpf.Tests/BootstrapperFixture.cs deleted file mode 100644 index 3cd57868d0..0000000000 --- a/tests/Wpf/Prism.Wpf.Tests/BootstrapperFixture.cs +++ /dev/null @@ -1,305 +0,0 @@ -using System; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using Xunit; -using Moq; -using Prism.Modularity; -using Prism.Regions; -using Prism.Regions.Behaviors; -using Prism.Mvvm; -using Prism.Wpf.Tests.Mocks.Views; -using Prism.Wpf.Tests.Mocks.ViewModels; -using Prism.Ioc; -using Prism.Wpf.Tests.Mocks; -using System.Runtime.Serialization; - -namespace Prism.Wpf.Tests -{ - - public class BootstrapperFixture - { - [Fact] - public void ModuleCatalogDefaultsToNull() - { - var bootstrapper = new DefaultBootstrapper(); - - Assert.Null(bootstrapper.BaseModuleCatalog); - } - - [Fact] - public void ShellDefaultsToNull() - { - var bootstrapper = new DefaultBootstrapper(); - - Assert.Null(bootstrapper.BaseShell); - } - - private static void CreateAndConfigureServiceLocatorForViewModelLocator() - { - var container = new MockContainerAdapter(); - container.ResolvedInstances.Add(typeof(MockViewModel), new MockViewModel()); - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => container); - } - - [Fact] - public void CreateModuleCatalogShouldInitializeModuleCatalog() - { - var bootstrapper = new DefaultBootstrapper(); - - bootstrapper.CallCreateModuleCatalog(); - - Assert.NotNull(bootstrapper.BaseModuleCatalog); - } - - [Fact] - public void RegisterFrameworkExceptionTypesShouldRegisterActivationException() - { - var bootstrapper = new DefaultBootstrapper(); - - bootstrapper.CallRegisterFrameworkExceptionTypes(); - - Assert.True(ExceptionExtensions.IsFrameworkExceptionRegistered( - typeof(ActivationException))); - } - - [Fact] - public void ConfigureRegionAdapterMappingsShouldRegisterItemsControlMapping() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithRegionAdapters(); - - var regionAdapterMappings = bootstrapper.CallConfigureRegionAdapterMappings(); - - Assert.NotNull(regionAdapterMappings); - Assert.NotNull(regionAdapterMappings.GetMapping(typeof(ItemsControl))); - } - - [Fact] - public void ConfigureRegionAdapterMappingsShouldRegisterContentControlMapping() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithRegionAdapters(); - - var regionAdapterMappings = bootstrapper.CallConfigureRegionAdapterMappings(); - - Assert.NotNull(regionAdapterMappings); - Assert.NotNull(regionAdapterMappings.GetMapping(typeof(ContentControl))); - } - - [Fact] - public void ConfigureRegionAdapterMappingsShouldRegisterSelectorMapping() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithRegionAdapters(); - - var regionAdapterMappings = bootstrapper.CallConfigureRegionAdapterMappings(); - - Assert.NotNull(regionAdapterMappings); - Assert.NotNull(regionAdapterMappings.GetMapping(typeof(Selector))); - } - - private static void CreateAndConfigureServiceLocatorWithRegionAdapters() - { - var container = new Mock(); - var regionBehaviorFactory = new RegionBehaviorFactory(container.Object); - container.Setup(sl => sl.Resolve(typeof(RegionAdapterMappings))).Returns(new RegionAdapterMappings()); - container.Setup(sl => sl.Resolve(typeof(SelectorRegionAdapter))).Returns(new SelectorRegionAdapter(regionBehaviorFactory)); - container.Setup(sl => sl.Resolve(typeof(ItemsControlRegionAdapter))).Returns(new ItemsControlRegionAdapter(regionBehaviorFactory)); - container.Setup(sl => sl.Resolve(typeof(ContentControlRegionAdapter))).Returns(new ContentControlRegionAdapter(regionBehaviorFactory)); - - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => container.Object); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddSevenDefaultBehaviors() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.Equal(8, bootstrapper.DefaultRegionBehaviorTypes.Count()); - } - - private static void CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors() - { - var containerExtension = new Mock(); - var regionBehaviorFactory = new RegionBehaviorFactory(containerExtension.Object); - containerExtension.Setup(sl => sl.Resolve(typeof(IRegionBehaviorFactory))).Returns(new RegionBehaviorFactory(containerExtension.Object)); - - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerExtension.Object); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddAutoPopulateRegionBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(AutoPopulateRegionBehavior.BehaviorKey)); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldBindRegionContextToDependencyObjectBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(BindRegionContextToDependencyObjectBehavior.BehaviorKey)); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddRegionActiveAwareBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(RegionActiveAwareBehavior.BehaviorKey)); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddSyncRegionContextWithHostBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(SyncRegionContextWithHostBehavior.BehaviorKey)); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddRegionManagerRegistrationBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(RegionManagerRegistrationBehavior.BehaviorKey)); - } - - [Fact] - public void ConfigureDefaultRegionBehaviorsShouldAddRegionLifetimeBehavior() - { - var bootstrapper = new DefaultBootstrapper(); - - CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors(); - - bootstrapper.CallConfigureDefaultRegionBehaviors(); - - Assert.True(bootstrapper.DefaultRegionBehaviorTypes.ContainsKey(RegionMemberLifetimeBehavior.BehaviorKey)); - } - - [Fact] - public void OnInitializedShouldRunLast() - { - var bootstrapper = new DefaultBootstrapper(); - - bootstrapper.Run(); - - Assert.True(bootstrapper.ExtraInitialization); - } - } - - internal class DefaultBootstrapper : Bootstrapper - { - public IRegionBehaviorFactory DefaultRegionBehaviorTypes; - public bool ExtraInitialization; - - public IModuleCatalog BaseModuleCatalog - { - get { return base.ModuleCatalog; } - set { base.ModuleCatalog = value; } - } - - public DependencyObject BaseShell - { - get { return base.Shell; } - set { base.Shell = value; } - } - - public void CallCreateModuleCatalog() - { - this.ModuleCatalog = base.CreateModuleCatalog(); - } - - public RegionAdapterMappings CallConfigureRegionAdapterMappings() - { - return base.ConfigureRegionAdapterMappings(); - } - - public void CallConfigureViewModelLocator() - { - base.ConfigureViewModelLocator(); - } - - public override void Run(bool runWithDefaultConfiguration) - { - Assert.False(this.ExtraInitialization); - } - - protected override void OnInitialized() - { - this.ExtraInitialization = true; - } - - protected override DependencyObject CreateShell() - { - throw new NotImplementedException(); - } - - protected override void InitializeShell() - { - throw new NotImplementedException(); - } - - public void CallRegisterFrameworkExceptionTypes() - { - RegisterFrameworkExceptionTypes(); - } - - protected override void RegisterFrameworkExceptionTypes() - { - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(ActivationException)); - } - - public IRegionBehaviorFactory CallConfigureDefaultRegionBehaviors() - { - this.DefaultRegionBehaviorTypes = base.ConfigureDefaultRegionBehaviors(); - return this.DefaultRegionBehaviorTypes; - } - - protected override IContainerExtension CreateContainerExtension() - { - return null; - } - } - - public class ActivationException : Exception - { - public ActivationException() - { - } - } -} diff --git a/tests/Wpf/Prism.Wpf.Tests/PrismBootstapperBaseFixture.cs b/tests/Wpf/Prism.Wpf.Tests/PrismBootstapperBaseFixture.cs index dc8174c953..fd7080b1d2 100644 --- a/tests/Wpf/Prism.Wpf.Tests/PrismBootstapperBaseFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/PrismBootstapperBaseFixture.cs @@ -267,13 +267,13 @@ protected override IModuleCatalog CreateModuleCatalog() return moduleCatalog; } - protected override Window CreateShell() + protected override DependencyObject CreateShell() { CreateShellWasCalled = true; return null; } - protected override void InitializeShell(Window shell) + protected override void InitializeShell(DependencyObject shell) { InitializeShellWasCalled = false; } diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs index 1c09fa088e..33e1ab5eb3 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs @@ -363,4 +363,11 @@ public TestRegionNavigationContentLoader(IContainerExtension container) public class TestView { } } + + public class ActivationException : Exception + { + public ActivationException() + { + } + } }