87 lines
5.7 KiB
Markdown
87 lines
5.7 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- Common/DTS.Common.CPU/CPUModule.cs
|
||
|
|
generated_at: "2026-04-16T11:34:07.271819+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "5a3256f83f5993a9"
|
||
|
|
---
|
||
|
|
|
||
|
|
# Documentation: DTS.Common.CPU.CPUModule
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
This module serves as the initialization logic for the "CPU" component within a modular WPF application built on the Microsoft Prism framework. It is responsible for registering the `CPUEngine` implementation with the Unity dependency injection container and providing assembly-level metadata (name and image) used by the main application shell to display available components.
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### Class: `CPUModule`
|
||
|
|
Implements `IModule` (from `Microsoft.Practices.Prism.Modularity`). This is the entry point for the module logic.
|
||
|
|
|
||
|
|
* **Constructor**: `CPUModule(IUnityContainer unityContainer)`
|
||
|
|
* Accepts a Unity container instance via constructor injection.
|
||
|
|
* **Method**: `void Initialize()`
|
||
|
|
* Registers type mappings in the Unity container.
|
||
|
|
* **Registration**: `ICPUEngine` maps to `CPUEngine`.
|
||
|
|
* **Commented Code**: Contains a commented-out registration for `IPropertyViewModel`.
|
||
|
|
|
||
|
|
### Class: `CPUNameAttribute`
|
||
|
|
Inherits from `TextAttribute`. Provides the assembly name metadata.
|
||
|
|
|
||
|
|
* **Constructor**: `CPUNameAttribute()` / `CPUNameAttribute(string s)`
|
||
|
|
* The string argument `s` is accepted but ignored.
|
||
|
|
* **Property**: `string AssemblyName` (read-only)
|
||
|
|
* Returns the hardcoded string `"CPUAsssembly"`.
|
||
|
|
* **Method**: `Type GetAttributeType()`
|
||
|
|
* Returns `typeof(TextAttribute)`.
|
||
|
|
* **Method**: `string GetAssemblyName()`
|
||
|
|
* Returns the value of the `AssemblyName` property.
|
||
|
|
|
||
|
|
### Class: `CUPImageAttribute`
|
||
|
|
Inherits from `ImageAttribute`. Provides assembly image and categorization metadata. Note the class name spelling "CUP".
|
||
|
|
|
||
|
|
* **Constructor**: `CUPImageAttribute()` / `CUPImageAttribute(string s)`
|
||
|
|
* The string argument `s` is accepted but ignored. Initializes the image resource.
|
||
|
|
* **Property**: `BitmapImage AssemblyImage` (read-only)
|
||
|
|
* Retrieves an image using `AssemblyInfo.GetImage(AssemblyNames.CPU.ToString())`.
|
||
|
|
* **Property**: `string AssemblyName` (read-only)
|
||
|
|
* Returns `AssemblyNames.CPU.ToString()`.
|
||
|
|
* **Property**: `string AssemblyGroup` (read-only)
|
||
|
|
* Returns `eAssemblyGroups.Viewer.ToString()`.
|
||
|
|
* **Property**: `eAssemblyRegion AssemblyRegion` (read-only)
|
||
|
|
* Returns `eAssemblyRegion.NotAssigned`.
|
||
|
|
* **Methods**:
|
||
|
|
* `Type GetAttributeType()`: Returns `typeof(ImageAttribute)`.
|
||
|
|
* `BitmapImage GetAssemblyImage()`: Returns `AssemblyImage`.
|
||
|
|
* `string GetAssemblyName()`: Returns `AssemblyName`.
|
||
|
|
* `eAssemblyRegion GetAssemblyRegion()`: Returns `AssemblyRegion`.
|
||
|
|
* `string GetAssemblyGroup()`: Returns `AssemblyGroup`.
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
|
||
|
|
* **Hardcoded Name**: The `CPUNameAttribute` always returns the string `"CPUAsssembly"`, regardless of constructor arguments.
|
||
|
|
* **Fixed Group/Region**: The `CUPImageAttribute` always defines the module group as `"Viewer"` and the region as `NotAssigned`.
|
||
|
|
* **Singleton Registration**: The `CPUModule` class comment implies the intent to register components as singletons, though `RegisterType` (used for `ICPUEngine`) typically registers a transient mapping by default in Unity unless a `ContainerControlledLifetimeManager` is specified. The specific lifetime manager is not visible in the source, so the "singleton" behavior mentioned in comments is not strictly enforced by the code shown.
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
|
||
|
|
### Internal Dependencies
|
||
|
|
* **`DTS.Common.Interface`**: Required for `ICPUEngine`, `TextAttribute`, `ImageAttribute`, `IUnityContainer` (if defined there), and `IModule` (if abstracted).
|
||
|
|
* **`DTS.Common.CPU`**: The namespace itself contains `CPUEngine` (referenced in `Initialize` but not defined in the file).
|
||
|
|
* **`AssemblyInfo`**: Used statically to fetch images (source not provided, assumed to be a helper class).
|
||
|
|
* **`AssemblyNames`**: An enum or constant class used to identify the CPU module (source not provided).
|
||
|
|
* **`eAssemblyGroups`**: An enum defining module groups (source not provided).
|
||
|
|
* **`eAssemblyRegion`**: An enum defining UI regions (source not provided).
|
||
|
|
|
||
|
|
### External Dependencies
|
||
|
|
* **`System.ComponentModel.Composition`**: Used for the `[Export]` attribute.
|
||
|
|
* **`System.Windows.Media.Imaging`**: Used for `BitmapImage`.
|
||
|
|
* **`Microsoft.Practices.Prism.Modularity`**: Used for `IModule` and `[Module]` attribute.
|
||
|
|
* **`Microsoft.Practices.Unity`**: Used for `IUnityContainer` and dependency injection APIs.
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
|
||
|
|
* **Typo in Attribute Class Name**: The class is named `CUPImageAttribute` (C-U-P) instead of `CPUImageAttribute`. The assembly attribute usage at the top `[assembly: CUPImage()]` matches this typo, so it functions correctly, but the naming is inconsistent.
|
||
|
|
* **Typo in Assembly Name String**: `CPUNameAttribute` returns the string `"CPUAsssembly"` (with three 's' characters). This may cause issues if other parts of the system expect "CPUAssembly" or "CPU".
|
||
|
|
* **Ignored Constructor Parameters**: Both attribute constructors accept a string parameter `s` but do not use it. This creates a misleading API where a developer might assume they can set a custom name or value.
|
||
|
|
* **Side Effects in Property Getters**: The `AssemblyImage` property getter in `CUPImageAttribute` modifies the private field `_img` (`_img = AssemblyInfo.GetImage(...)`). This is a side effect inside a getter, which violates standard C# property guidelines and could lead to unexpected behavior or performance hits during property access.
|
||
|
|
* **Commented Code**: The `Initialize` method contains commented-out code for `IPropertyViewModel`, suggesting incomplete features or tech debt regarding property view registration.
|