Files
DP44/enriched-qwen3-coder-next/DTS Viewer/DTS.Viewer.Loader.md

70 lines
5.8 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
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-16T13:36:22.431378+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "d7175f2d8133b4b4"
---
# Documentation: DTS.Viewer.Loader
## 1. Purpose
The `DTS.Viewer.Loader` assembly serves as the initialization and bootstrapping layer for a WPF-based DTS Viewer application. It leverages the Microsoft Prism framework (specifically `UnityBootstrapper`) to configure dependency injection, dynamically load runtime modules from a predefined directory, and initialize the primary application shell (`ShellView`) and viewer session. Its role is to act as the entry point that orchestrates the composition of the UI and backend services before handing control over to the loaded modules.
## 2. Public Interface
### Class: `App` (inherits `Application`)
* **`App_OnStartup(object sender, StartupEventArgs e)`**: Private event handler for the application startup. It instantiates `ViewerLoaderSession` and invokes `CreateSession()` to initialize the application logic.
### Class: `MainWindow` (inherits `Window`)
* **`MainWindow()`**: Constructor. Calls `InitializeComponent()`. Note: Based on `Bootstrapper` logic, this window appears to be unused in the main startup flow, which favors `ShellView`.
### Class: `ViewerLoaderSession`
* **`CreateSession()`**: Public method that initializes the Prism infrastructure. It creates the `Bootstrapper`, resolves the `IUnityContainer`, `IEventAggregator`, `IServiceLocator`, and `IRegionManager`, and then starts the viewer session via `IViewerModule`.
* **`Terminate()`**: Public method intended for shutdown/cleanup logic (currently empty implementation).
* **Properties**:
* `_unityContainer` (`IUnityContainer`): Provides access to the Unity dependency injection container.
* `ServiceLocator` (`IServiceLocator`): Provides access to the service locator abstraction.
* `EventAggregator` (`IEventAggregator`): Provides access to the Prism event aggregation system.
* `RegionManager` (`IRegionManager`): Manages the visual regions of the application.
### Class: `Bootstrapper` (inherits `UnityBootstrapper`)
* **`ConfigureContainer()`**: Override that registers `IShellView` and `IShellViewModel` with the Unity container.
* **`CreateShell()`**: Override that resolves the shell view model, initializes the view, sets its data context, and returns the `ShellView` instance.
* **`CreateModuleCatalog()`**: Override that initializes an `AggregateModuleCatalog`.
* **`ConfigureModuleCatalog()`**: Override that adds a `DirectoryModuleCatalog` pointing to the plugin folder defined in settings.
* **`InitializeModules()`**: Override that registers `IDTSRegionManager` as a singleton and initializes modules.
## 3. Invariants
* **Singleton ViewModels**: `IShellViewModel` is registered with a `ContainerControlledLifetimeManager`, ensuring only one instance of the Shell ViewModel exists during the application lifetime.
* **Region Adapter Mappings**: The `ConfigureRegionAdapterMappings` method is explicitly overridden to return `null`. This implies that region adapters must be defined elsewhere or are not used/required by the shell initialization logic in this specific bootstrapper.
* **Module Loading Location**: Modules are strictly loaded from the directory specified in `Properties.Settings.Default.PluginFolder`.
* **Shell Initialization**: The `CreateShell` method requires `IShellViewModel` to be resolvable; otherwise, it returns a generic `DependencyObject` (which effectively results in no main window being shown).
## 4. Dependencies
### External Dependencies
* **Microsoft.Practices.Prism**: Specifically `Events`, `Modularity`, `Regions`, and `UnityExtensions`.
* **Microsoft.Practices.Unity**: Used for Dependency Injection (`IUnityContainer`, `ContainerControlledLifetimeManager`).
* **Microsoft.Practices.ServiceLocation**: Used for the `IServiceLocator` abstraction.
* **System.Windows**: WPF core libraries for `Application`, `Window`, `DependencyObject`.
### Internal Dependencies
* **DTS.Common**: Referenced in `ViewerLoaderSession`.
* **DTS.Common.Base**: Referenced in `ViewerLoaderSession`.
* **DTS.Common.Classes**: Referenced in `ViewerLoaderSession`.
* **DTS.Common.Core.PluginLib**: Used for `PluginManager` and `IModule`.
* **DTS.Common.Interface**: Used for interfaces such as `IShellView`, `IShellViewModel`, `IViewerModule`, `IViewerMainViewModel`, `IDTSRegionManager`.
## 5. Gotchas
* **Hardcoded Configuration Path**: In `ViewerLoaderSession.CreateSession()`, the path `@"C:\devDTS\RunTimeModules\DTS.Viewer.dll.config"` is hardcoded as an argument to `viewerModule.StartSession`. This will likely cause the application to fail on machines without this specific directory structure.
* **Swallowed Exception**: `Bootstrapper.ConfigureContainer()` catches `System.Threading.SynchronizationLockException` inside a `try/catch` block with an empty catch body. This suppresses a potential threading error which could mask underlying race conditions.
* **Unused MainWindow**: The project contains a `MainWindow` class, but the `Bootstrapper.CreateShell()` method explicitly creates and shows a `ShellView`. The `MainWindow` appears to be dead code or a legacy artifact.
* **Memory Constraints**: The source code comments in `ViewerLoaderSession` explicitly warn against re-creating the bootstrapper, noting that it loads ~40MB into memory and cannot be easily unloaded.
* **Application Exit Code**: The `Bootstrapper_Closing` event handler calls `Application.Current.Shutdown(1)`, passing an exit code of `1`, which conventionally indicates an error or abnormal termination, even though this is the standard closing flow.