74 lines
5.5 KiB
Markdown
74 lines
5.5 KiB
Markdown
---
|
|
source_files:
|
|
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/AddCalculatedChannelModule.cs
|
|
generated_at: "2026-04-16T13:45:51.254810+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "a6eff6c72a8470eb"
|
|
---
|
|
|
|
# Documentation: DTS.Viewer.AddCalculatedChannel Module
|
|
|
|
## 1. Purpose
|
|
This module serves as the entry point for the "Add Calculated Channel" feature within the DTS Viewer application. It is responsible for self-registering its View and ViewModel components with the Unity dependency injection container and providing assembly-level metadata (such as display name, icon, and region assignment) to the main application shell for module discovery and UI composition.
|
|
|
|
## 2. Public Interface
|
|
|
|
### `AddCalculatedChannelModule`
|
|
The main Prism module class responsible for dependency registration.
|
|
|
|
* **`AddCalculatedChannelModule(IUnityContainer unityContainer)`**
|
|
* Constructor that accepts an `IUnityContainer` instance via dependency injection and stores it in a private readonly field `_unityContainer`.
|
|
* **`void RegisterTypes(IContainerRegistry containerRegistry)`**
|
|
* Implements `IModule.RegisterTypes`. Calls the private `Initialize()` method to perform type registrations.
|
|
* **`void OnInitialized(IContainerProvider containerProvider)`**
|
|
* Implements `IModule.OnInitialized`. Currently contains no implementation logic.
|
|
|
|
### `AddCalculatedChannelModuleNameAttribute`
|
|
An assembly-level attribute used to expose the module's name.
|
|
|
|
* **`string AssemblyName { get; }`**
|
|
* Returns the string representation of `AssemblyNames.AddCalculatedChannel`.
|
|
* **`Type GetAttributeType()`**
|
|
* Returns `typeof(TextAttribute)`.
|
|
* **`string GetAssemblyName()`**
|
|
* Returns the value of the `AssemblyName` property.
|
|
|
|
### `AddCalculatedChannelModuleImageAttribute`
|
|
An assembly-level attribute used to expose the module's image, group, and region metadata.
|
|
|
|
* **`BitmapImage AssemblyImage { get; }`**
|
|
* Retrieves the module's icon using `AssemblyInfo.GetImage`.
|
|
* **`string AssemblyName { get; }`**
|
|
* Returns the string representation of `AssemblyNames.AddCalculatedChannel`.
|
|
* **`string AssemblyGroup { get; }`**
|
|
* Returns `eAssemblyGroups.Viewer.ToString()`.
|
|
* **`eAssemblyRegion AssemblyRegion { get; }`**
|
|
* Returns `eAssemblyRegion.AddCalculatedChannelRegion`.
|
|
* **`BitmapImage GetAssemblyImage()` / `string GetAssemblyName()` / `string GetAssemblyGroup()` / `eAssemblyRegion GetAssemblyRegion()`**
|
|
* Accessor methods returning the values of their corresponding properties.
|
|
|
|
## 3. Invariants
|
|
* **Naming Consistency:** The `AssemblyName` property in both attribute classes must always resolve to `AssemblyNames.AddCalculatedChannel.ToString()`.
|
|
* **Region Assignment:** The module is strictly assigned to the `eAssemblyRegion.AddCalculatedChannelRegion` region.
|
|
* **Group Assignment:** The module belongs strictly to the `eAssemblyGroups.Viewer` group.
|
|
* **Registration Mapping:** The `Initialize` method maps the interface `IAddCalculatedChannelView` to the concrete implementation `AddCalculatedChannelView`, and `IAddCalculatedChannelViewModel` to `AddCalculatedChannelViewModel`.
|
|
|
|
## 4. Dependencies
|
|
|
|
### Internal Dependencies
|
|
* **`DTS.Common`**: Used for `AssemblyNames`, `eAssemblyGroups`, `eAssemblyRegion`, and `AssemblyInfo`.
|
|
* **`DTS.Common.Interface`**: Provides the base classes `TextAttribute` and `ImageAttribute`.
|
|
* **`DTS.Viewer.AddCalculatedChannel`**: The module references concrete types `AddCalculatedChannelView` and `AddCalculatedChannelViewModel` defined within its own scope (though the file defining them is not provided here, they are referenced in `Initialize`).
|
|
|
|
### External Dependencies
|
|
* **`Prism.Ioc`**: Provides `IContainerProvider` and `IContainerRegistry`.
|
|
* **`Prism.Modularity`**: Provides `IModule` and `ModuleAttribute`.
|
|
* **`Unity`**: Provides `IUnityContainer` (used for specific Unity registration methods).
|
|
* **`System.Windows.Media.Imaging`**: Provides `BitmapImage` for image handling.
|
|
|
|
## 5. Gotchas
|
|
* **Misleading Singleton Comment:** The comment in `Initialize()` states: *"Register View & View-Model with Unity dependency injection container as a singleton."* However, the code uses `_unityContainer.RegisterType<...>()`. In Unity, `RegisterType` registers a transient mapping (new instance per request) by default, not a singleton. To register as a singleton, `ContainerControlledLifetimeManager` should be used. The code behavior contradicts the documentation.
|
|
* **Side Effects in Property Getters:** In `AddCalculatedChannelModuleImageAttribute`, the getter for `AssemblyImage` modifies the private field `_img` (lazy initialization pattern inside a property getter). This is a side effect that could cause unexpected behavior if the property is accessed multiple times or inspected in a debugger, though the result is cached.
|
|
* **Unused Constructor Parameter:** Both attribute classes define a constructor taking a `string s`, but the parameter is never used inside the constructor body. This suggests the parameter exists solely to satisfy a reflection-based instantiation requirement or is legacy code.
|
|
* **Dual Registration Approach:** The module uses `IUnityContainer` (field injection) to call `RegisterType`, but the `RegisterTypes` method signature provides an `IContainerRegistry`. This mixes Prism's abstract container registry with the concrete Unity container. While valid if the backing container is Unity, it couples the module strictly to the Unity container rather than remaining container-agnostic. |