Files
DP44/DTS Viewer/DTS.Viewer.Loader/Bootstrapper.cs

118 lines
5.2 KiB
C#
Raw Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.Windows;
using DTS.Common;
using DTS.Common.Interface;
using DTS.Common.Core.PluginLib;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
// ReSharper disable InconsistentNaming
namespace DTS.Viewer.Loader
{
/// <summary>
/// https://msdn.microsoft.com/en-us/library/ff921075(v=pandp.20).aspx
/// </summary>
public class Bootstrapper : UnityBootstrapper
{
public IServiceLocator _serviceLocator { get; private set; }
public IEventAggregator _EventAggregator { get; private set; }
protected override void ConfigureContainer()
{
Container.RegisterType<IShellView, ShellView>();
Container.RegisterType<IShellViewModel, ShellViewModel>(new ContainerControlledLifetimeManager());
try
{
base.ConfigureContainer();
}
catch (System.Threading.SynchronizationLockException e)
{
}
}
/// <summary>
/// Returns null - not to interfere with Viewer app RegionAdapterMappings
/// </summary>
/// <returns></returns>
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
return null;
//var regionAdapterMappings = base.ConfigureRegionAdapterMappings();
//regionAdapterMappings.RegisterMapping(typeof(StackPanel), ServiceLocator.Current.GetInstance<StackPanelRegionAdapter>());
//return regionAdapterMappings;
}
/// <summary>
/// The CreateShell method allows a developer to specify the top-level window for a Prism application.
/// The shell is usually the MainWindow or MainPage. Implement this method by returning an instance of
/// your application's shell class. In a Prism application, you can create the shell object, or resolve
/// it from the container, depending on your application's requirements.
/// </summary>
/// <returns></returns>
protected override DependencyObject CreateShell()
{
Container = ServiceLocator.Current.GetInstance<IUnityContainer>();
_EventAggregator = Container.Resolve<IEventAggregator>();
_serviceLocator = Container.Resolve<IServiceLocator>();
var viewmodel = Container.TryResolve<IShellViewModel>();
if (viewmodel == null) return new DependencyObject();
var view = viewmodel.View;
viewmodel.Initialize(this);
((ShellView)view).Visibility = Visibility.Visible;
((ShellView)view).Closing += Bootstrapper_Closing;
view.DataContext = viewmodel;
return ServiceLocator.Current.GetInstance<ShellView>();
}
/// <summary>
/// Shutdown the application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Bootstrapper_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Current.Shutdown(1);
}
/// <summary>
/// Returns the module catalog that will be used to initialize the modules.
/// </summary>
/// <returns>
/// An instance of <see cref="IModuleCatalog"/> that will be used to initialize the modules.
/// </returns>
protected override IModuleCatalog CreateModuleCatalog()
{
// The module catalog is used by the ModuleManager and ModuleLoader components, which are responsible for downloading the modules.
return new AggregateModuleCatalog();
}
/// <summary>
/// Modules are packages of functionality that can be independently developed, tested, and (optionally) deployed.
/// In a composite application, modules must be discovered and loaded at run time by the host application.
/// The module catalog is used by the ModuleManager and ModuleLoader components, which are responsible for downloading the modules.
/// Modules are copied to a directory as part of a post-build step. These modules are not referenced in the project and are discovered by inspecting a directory.
/// Module projects have a post-build step to copy themselves into that directory.
/// </summary>
protected override void ConfigureModuleCatalog()
{
var directoryCatalog = new DirectoryModuleCatalog { ModulePath = Properties.Settings.Default.PluginFolder };
((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog);
}
protected override void InitializeModules()
{
// Register the DataProRegionManager with Unity dependency injection container as a singleton.
Container.RegisterType<IDTSRegionManager, DTSRegionManager>(new ContainerControlledLifetimeManager(), new InjectionMember[] { });
base.InitializeModules();
}
}
}