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 { /// /// https://msdn.microsoft.com/en-us/library/ff921075(v=pandp.20).aspx /// public class Bootstrapper : UnityBootstrapper { public IServiceLocator _serviceLocator { get; private set; } public IEventAggregator _EventAggregator { get; private set; } protected override void ConfigureContainer() { Container.RegisterType(); Container.RegisterType(new ContainerControlledLifetimeManager()); try { base.ConfigureContainer(); } catch (System.Threading.SynchronizationLockException e) { } } /// /// Returns null - not to interfere with Viewer app RegionAdapterMappings /// /// protected override RegionAdapterMappings ConfigureRegionAdapterMappings() { return null; //var regionAdapterMappings = base.ConfigureRegionAdapterMappings(); //regionAdapterMappings.RegisterMapping(typeof(StackPanel), ServiceLocator.Current.GetInstance()); //return regionAdapterMappings; } /// /// 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. /// /// protected override DependencyObject CreateShell() { Container = ServiceLocator.Current.GetInstance(); _EventAggregator = Container.Resolve(); _serviceLocator = Container.Resolve(); var viewmodel = Container.TryResolve(); 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(); } /// /// Shutdown the application /// /// /// void Bootstrapper_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Application.Current.Shutdown(1); } /// /// Returns the module catalog that will be used to initialize the modules. /// /// /// An instance of that will be used to initialize the modules. /// 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(); } /// /// 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. /// 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(new ContainerControlledLifetimeManager(), new InjectionMember[] { }); base.InitializeModules(); } } }