--- source_files: - DTS Viewer/DTS.Viewer.Loader/App.xaml.cs - DTS Viewer/DTS.Viewer.Loader/MainWindow.xaml.cs - DTS Viewer/DTS.Viewer.Loader/ViewerLoaderSession.cs - DTS Viewer/DTS.Viewer.Loader/Bootstrapper.cs generated_at: "2026-04-16T10:58:04.030267+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "d7175f2d8133b4b4" --- # DTS.Viewer.Loader Module Documentation ## 1. Purpose The `DTS.Viewer.Loader` module serves as the entry point and bootstrapping layer for a Prism-based WPF viewer application. Its primary role is to initialize the Unity dependency injection container, configure module discovery via directory-based cataloging, and orchestrate the startup of the main viewer session. This module acts as the composition root that wires together the shell view, region management, and dynamically loaded plugins. --- ## 2. Public Interface ### `App` (partial class, inherits `Application`) **File:** `App.xaml.cs` | Member | Signature | Description | |--------|-----------|-------------| | `App_OnStartup` | `private void App_OnStartup(object sender, StartupEventArgs e)` | Application startup event handler. Instantiates a `ViewerLoaderSession` and calls `CreateSession()` to initialize the application. | --- ### `MainWindow` (partial class, inherits `Window`) **File:** `MainWindow.xaml.cs` | Member | Signature | Description | |--------|-----------|-------------| | Constructor | `public MainWindow()` | Calls `InitializeComponent()`. Standard WPF window initialization. | --- ### `ViewerLoaderSession` **File:** `ViewerLoaderSession.cs` | Member | Signature | Description | |--------|-----------|-------------| | `_unityContainer` | `public IUnityContainer _unityContainer { get; private set; }` | Exposes the Unity dependency injection container after session creation. | | `ServiceLocator` | `public IServiceLocator ServiceLocator { get; private set; }` | Exposes the Prism service locator. | | `EventAggregator` | `public IEventAggregator EventAggregator { get; private set; }` | Exposes the Prism event aggregator for pub/sub messaging. | | `RegionManager` | `public IRegionManager RegionManager { get; private set; }` | Exposes the Prism region manager for view composition. | | Constructor | `public ViewerLoaderSession()` | Default constructor. No initialization performed. | | `CreateSession` | `public void CreateSession()` | Main initialization method. Creates the bootstrapper, resolves core services from the container, starts the viewer module, and sets the main region context on the shell viewmodel. | | `Terminate` | `public void Terminate()` | Called during application shutdown. Currently empty implementation. | | `GetRegisteredViewType` | `private Type GetRegisteredViewType(string name)` | Queries the Unity container registrations for a registered type matching the given name suffix. Returns the first match or default. | | `LoadPlugins` | `private List LoadPlugins()` | Uses `PluginManager.GetPluginManager()` to load plugin assemblies implementing `IModule` from a configuration file path. | --- ### `Bootstrapper` (inherits `UnityBootstrapper`) **File:** `Bootstrapper.cs` | Member | Signature | Description | |--------|-----------|-------------| | `_serviceLocator` | `public IServiceLocator _serviceLocator { get; private set; }` | Exposes the resolved service locator instance. | | `_EventAggregator` | `public IEventAggregator _EventAggregator { get; private set; }` | Exposes the resolved event aggregator instance. | | `ConfigureContainer` | `protected override void ConfigureContainer()` | Registers `IShellView` → `ShellView` and `IShellViewModel` → `ShellViewModel` (singleton) with the Unity container, then calls base implementation. | | `ConfigureRegionAdapterMappings` | `protected override RegionAdapterMappings ConfigureRegionAdapterMappings()` | Returns `null`. Region adapter configuration is intentionally disabled to avoid interfering with the viewer app's mappings. | | `CreateShell` | `protected override DependencyObject CreateShell()` | Resolves the shell viewmodel, initializes it, attaches a closing event handler, and returns the `ShellView` instance. | | `CreateModuleCatalog` | `protected override IModuleCatalog CreateModuleCatalog()` | Returns a new `AggregateModuleCatalog` instance for aggregating multiple module catalogs. | | `ConfigureModuleCatalog` | `protected override void ConfigureModuleCatalog()` | Creates a `DirectoryModuleCatalog` using the plugin folder path from `Properties.Settings.Default.PluginFolder` and adds it to the aggregate catalog. | | `InitializeModules` | `protected override void InitializeModules()` | Registers `IDTSRegionManager` → `DTSRegionManager` as a singleton, then calls base initialization. | | `Bootstrapper_Closing` | `void Bootstrapper_Closing(object sender, CancelEventArgs e)` | Event handler for shell closing; calls `Application.Current.Shutdown(1)`. | --- ## 3. Invariants 1. **Bootstrapper Singleton Pattern**: The `_bootstrapper` field in `ViewerLoaderSession` must only be created once. The `CreateBootstrapper()` method checks for null before instantiation and throws if creation fails. 2. **Container Availability**: The `_unityContainer`, `ServiceLocator`, `EventAggregator`, and `RegionManager` properties on `ViewerLoaderSession` are only valid after `CreateSession()` has been successfully called and `_bootstrapper` is non-null. 3. **Shell ViewModel Lifetime**: `ShellViewModel` is registered with `ContainerControlledLifetimeManager`, making it a singleton within the container. 4. **Module Path Configuration**: The module catalog depends on `Properties.Settings.Default.PluginFolder` being correctly configured; otherwise, module discovery will fail. 5. **Region Adapter Mappings**: `ConfigureRegionAdapterMappings()` returns `null` by design—this is intentional to prevent interference with the viewer application's existing region adapters. --- ## 4. Dependencies ### External Dependencies (Imports) | Namespace | Purpose | |-----------|---------| | `DTS.Common` | Common utilities and types | | `DTS.Common.Base` | Base classes | | `DTS.Common.Classes` | Common class implementations | | `DTS.Common.Core.PluginLib` | Plugin management infrastructure (`PluginManager`, `IModule`) | | `DTS.Common.Interface` | Core interfaces (`IShellView`, `IShellViewModel`, `IShellViewModel`, `IViewerModule`, `IViewerMainViewModel`, `IDTSRegionManager`) | | `Microsoft.Practices.Prism.Events` | `IEventAggregator` for event aggregation | | `Microsoft.Practices.Prism.Modularity` | `IModuleCatalog`, `DirectoryModuleCatalog`, `AggregateModuleCatalog` | | `Microsoft.Practices.Prism.Regions` | `IRegionManager`, `RegionAdapterMappings` | | `Microsoft.Practices.Prism.UnityExtensions` | `UnityBootstrapper` base class | | `Microsoft.Practices.ServiceLocation` | `IServiceLocator` | | `Microsoft.Practices.Unity` | `IUnityContainer`, `ContainerControlledLifetimeManager`, `InjectionMember` | | `System.Windows` | WPF core types (`Application`, `Window`, `DependencyObject`, `Visibility`) | ### Internal Dependencies - `ShellView` and `ShellViewModel` are resolved via Unity but their definitions are not included in the provided source files. - `DTSRegionManager` is referenced but not defined in the provided source. --- ## 5. Gotchas 1. **Hardcoded Configuration Path**: In `ViewerLoaderSession.CreateSession()`, the path `@"C:\devDTS\RunTimeModules\DTS.Viewer.dll.config"` is hardcoded in the call to `viewerModule.StartSession()`. This will likely fail on machines without this specific directory structure. 2. **SynchronizationLockException Swallowed**: In `Bootstrapper.ConfigureContainer()`, the `System.Threading.SynchronizationLockException` is caught but has an empty catch block with no logging or handling. This may mask threading issues. 3. **Bootstrapper Cannot Be Re-created**: As documented in the remarks on `_bootstrapper`, once modules are loaded into the `DirectoryModuleCatalog`, module initializers will not be called again on subsequent bootstrapper creations. The bootstrapper loads approximately 40 MB into memory and cannot be fully unloaded without additional effort. 4. **Commented-Out Code Blocks**: `ViewerLoaderSession.CreateSession()` contains significant commented-out code related to plugin loading and view registration, suggesting incomplete refactoring or alternative implementation paths that were abandoned. 5. **Region Adapter Mappings Disabled**: The `ConfigureRegionAdapterMappings()` override returns `null` and has commented-out code for `StackPanelRegionAdapter`. This may cause issues if region adapters are expected by other modules. 6. **Application Shutdown Code**: The `Bootstrapper_Closing` handler calls `Application.Current.Shutdown(1)` with exit code 1, which typically indicates an error condition. This may be unintentional. 7. **Null Check After Creation**: `CreateBootstrapper()` has a redundant null check after the try-catch block—the exception handling re-throws, so if execution reaches the second null check, the bootstrapper should always be non-null unless there's a race condition.