/// <summary> /// Runs the initialization sequence to configure the Prism application. /// </summary> protected virtual void Initialize() { ContainerLocator.SetContainerExtension(CreateContainerExtension); _containerExtension = ContainerLocator.Current; _moduleCatalog = CreateModuleCatalog(); RegisterRequiredTypes(_containerExtension); RegisterTypes(_containerExtension); _containerExtension.FinalizeExtension(); ConfigureModuleCatalog(_moduleCatalog); var regionAdapterMappings = _containerExtension.Resolve <RegionAdapterMappings>(); ConfigureRegionAdapterMappings(regionAdapterMappings); var defaultRegionBehaviors = _containerExtension.Resolve <IRegionBehaviorFactory>(); ConfigureDefaultRegionBehaviors(defaultRegionBehaviors); RegisterFrameworkExceptionTypes(); var shell = CreateShell(); if (shell != null) { MvvmHelpers.AutowireViewModel(shell); RegionManager.SetRegionManager(shell, _containerExtension.Resolve <IRegionManager>()); RegionManager.UpdateRegions(); InitializeShell(shell); } InitializeModules(); }
/// <summary> /// Configure <see cref="IDialogWindow"/> content. /// </summary> /// <param name="dialogName">The name of the dialog to show.</param> /// <param name="window">The hosting window.</param> /// <param name="parameters">The parameters to pass to the dialog.</param> protected virtual async Task ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters) { var content = _containerExtension.Resolve <object>(dialogName); if (!(content is FrameworkElement dialogContent)) { throw new NullReferenceException("A dialog's content must be a FrameworkElement"); } MvvmHelpers.AutowireViewModel(dialogContent); if (!(dialogContent.DataContext is IDialogAware viewModel)) { throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface"); } if (!(dialogContent.DataContext is IDialogAsyncAware asyncviewModel)) { throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAsyncAware interface"); } if (viewModel != null) { ConfigureDialogWindowProperties(window, dialogContent, viewModel); viewModel.OnDialogOpened(parameters); } else if (asyncviewModel != null) { ConfigureDialogWindowProperties(window, dialogContent, asyncviewModel); await asyncviewModel.OnDialogOpenedAsync(parameters); } }
private async Task ConfigureContentDialogContent(ContentDialog dialog, IDialogParameters parameters) { MvvmHelpers.AutowireViewModel(dialog); object viewModel = dialog.DataContext; Initialize(parameters, viewModel); await InitializeAsync(parameters, viewModel); }
/// <summary> /// Provides a new item for the region based on the supplied candidate target contract name. /// </summary> /// <param name="candidateTargetContract">The target contract to build.</param> /// <returns>An instance of an item to put into the <see cref="IRegion"/>.</returns> protected virtual object CreateNewRegionItem(string candidateTargetContract) { object newRegionItem; try { newRegionItem = _container.Resolve <object>(candidateTargetContract); MvvmHelpers.AutowireViewModel(newRegionItem); } catch (Exception e) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.CannotCreateNavigationTarget, candidateTargetContract), e); } return(newRegionItem); }
/// <summary> /// Configure <see cref="IDialogWindow"/> content. /// </summary> /// <param name="dialogName">The name of the dialog to show.</param> /// <param name="window">The hosting window.</param> /// <param name="parameters">The parameters to pass to the dialog.</param> protected virtual void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters) { var content = _containerExtension.Resolve <object>(dialogName); if (!(content is FrameworkElement dialogContent)) { throw new NullReferenceException("A dialog's content must be a FrameworkElement"); } MvvmHelpers.AutowireViewModel(dialogContent); if (!(dialogContent.DataContext is IDialogAware viewModel)) { throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface"); } ConfigureDialogWindowProperties(window, dialogContent, viewModel); MvvmHelpers.ViewAndViewModelAction <IDialogAware>(viewModel, d => d.OnDialogOpened(parameters)); }
/// <summary> /// Provides a new item for the region based on the supplied candidate target contract name. /// </summary> /// <param name="candidateTargetContract">The target contract to build.</param> /// <returns>An instance of an item to put into the <see cref="IRegion"/>.</returns> protected virtual object CreateNewRegionItem(string candidateTargetContract) { try { var view = ContainerLocator.Container.Resolve <object>(candidateTargetContract); MvvmHelpers.AutowireViewModel(view); return(view); } catch (ContainerResolutionException) { throw; } catch (Exception e) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.CannotCreateNavigationTarget, candidateTargetContract), e); } }
/// <summary> /// Runs the initialization sequence to configure the Prism application. /// </summary> protected virtual void Initialize() { ContainerLocator.SetContainerExtension(CreateContainerExtension); _containerExtension = ContainerLocator.Current; _moduleCatalog = CreateModuleCatalog(); RegisterRequiredTypes(_containerExtension); RegisterTypes(_containerExtension); _containerExtension.FinalizeExtension(); ConfigureModuleCatalog(_moduleCatalog); RegisterFrameworkExceptionTypes(); var shell = CreateShell(); if (shell != null) { MvvmHelpers.AutowireViewModel(shell); InitializeShell(shell); } InitializeModules(); }
/// <summary> /// Runs the initialization sequence to configure the Prism application. /// </summary> public virtual void Initialize() { ContainerLocator.SetContainerExtension(CreateContainerExtension); _containerExtension = ContainerLocator.Current; _moduleCatalog = CreateModuleCatalog(); RegisterRequiredTypes(_containerExtension); RegisterTypes(_containerExtension); _containerExtension.FinalizeExtension(); ConfigureModuleCatalog(_moduleCatalog); var regionAdapterMappins = _containerExtension.Resolve <RegionAdapterMappings>(); ConfigureRegionAdapterMappings(regionAdapterMappins); var defaultRegionBehaviors = _containerExtension.Resolve <IRegionBehaviorFactory>(); ConfigureDefaultRegionBehaviors(defaultRegionBehaviors); RegisterFrameworkExceptionTypes(); var shell = CreateShell(); if (shell != null) { MvvmHelpers.AutowireViewModel(shell); InitializeShell(shell); void FinalizeInitialization() { RegionManager.SetRegionManager(shell, _containerExtension.Resolve <IRegionManager>()); RegionManager.UpdateRegions(); InitializeModules(); OnInitialized(); } if (shell is FrameworkElement fe) { void OnLoaded(object sender, object args) { FinalizeInitialization(); fe.Loaded -= OnLoaded; } #if HAS_UNO // Uno currently loads items earlier than UWP, so we can check // for the IsLoaded property. UWP got that property in SDK 17763, // meaning that the condition can be removed once the SDK is updated // in Prism.Uno. if (fe.IsLoaded) { FinalizeInitialization(); } else #endif { // We need to delay the initialization after the shell has been loaded, otherwise // the visual tree is not materialized for the RegionManager to be available. // See https://github.com/PrismLibrary/Prism/issues/2102 for more details. fe.Loaded += OnLoaded; } } else { FinalizeInitialization(); } } }
protected virtual void Initialize() { this.Logger = this.CreateLogger(); if (this.Logger == null) { throw new InvalidOperationException("log created faild"); } ConfigureViewModelLocator(); this.Logger.Log("log created success", LogLevel.Debug, Priority.Low); this.Logger.Log("create module catelog", LogLevel.Debug, Priority.Low); this.ModuleCatalog = this.CreateModuleCatalog(); if (this.ModuleCatalog == null) { throw new InvalidOperationException("module catelog null"); } this.Logger.Log("configuring module catelog", LogLevel.Debug, Priority.Low); ConfigureModuleCatalog(ModuleCatalog); this.Logger.Log("creating careful container", LogLevel.Debug, Priority.Low); this.Container = this.CreateContainer(); if (this.Container == null) { throw new InvalidOperationException("careful container null"); } this.Logger.Log("configuring careful container", LogLevel.Debug, Priority.Low); this.ConfigureContainer(); this.Logger.Log("confguring service locator", LogLevel.Debug, Priority.Low); this.ConfigureServiceLocator(); ContainerLocator.SetContainerExtension(() => CreateContainerExtension()); ContainerExtension = ContainerLocator.Current; //To Do :region register //RegisterRequiredTypes(ContainerExtension); //RegisterTypes(ContainerExtension); //ContainerExtension.FinalizeExtension(); //this.Logger.Log("configuring region adapter", LogLevel.Debug, Priority.Low); //this.ConfigureRegionAdapterMappings(); //this.Logger.Log("configuring default region behaviors", LogLevel.Debug, Priority.Low); //this.ConfigureDefaultRegionBehaviors(); //this.Logger.Log("registering frameworkd excetion type", LogLevel.Debug, Priority.Low); this.RegisterFrameworkExceptionTypes(); this.Logger.Log("create shell", LogLevel.Debug, Priority.Low); this.Shell = this.CreateShell(); if (this.Shell != null) { MvvmHelpers.AutowireViewModel(Shell); this.Logger.Log("setting region management", LogLevel.Debug, Priority.Low); RegionManager.SetRegionManager(this.Shell, this.Container.GetInstance <IRegionManager>()); this.Logger.Log("updating region", LogLevel.Debug, Priority.Low); RegionManager.UpdateRegions(); this.Logger.Log("initialize shell", LogLevel.Debug, Priority.Low); this.OnInitialized(); } if (this.Container.IsRegistered <IModuleManager>()) { this.Logger.Log("initialize module", LogLevel.Debug, Priority.Low); this.InitializeModules(); } this.Logger.Log("bootstrapper sequence completed", LogLevel.Debug, Priority.Low); //var regionAdapterMappins = ContainerExtension.Resolve<RegionAdapterMappings>(); //ConfigureRegionAdapterMappings(regionAdapterMappins); //var defaultRegionBehaviors = ContainerExtension.Resolve<IRegionBehaviorFactory>(); //ConfigureDefaultRegionBehaviors(defaultRegionBehaviors); //RegisterFrameworkExceptionTypes(); }