120 lines
6.2 KiB
Markdown
120 lines
6.2 KiB
Markdown
|
|
---
|
|||
|
|
source_files:
|
|||
|
|
- DataPRO/Modules/Menu/HamburgerMenu/HamburgerMenuModule.cs
|
|||
|
|
generated_at: "2026-04-16T04:48:16.508256+00:00"
|
|||
|
|
model: "Qwen/Qwen3-Coder-Next-FP8"
|
|||
|
|
schema_version: 1
|
|||
|
|
sha256: "7a5beb8ec708c422"
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
# HamburgerMenu
|
|||
|
|
|
|||
|
|
## Documentation: HamburgerMenuModule
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 1. Purpose
|
|||
|
|
The `HamburgerMenuModule` is a Prism module responsible for registering the view and view model for the application’s hamburger menu UI component into the Unity dependency injection container. It enables modular composition of the UI by exposing the hamburger menu as a reusable, injectable component within the Prism-based application shell. The module also contributes metadata—specifically, an assembly name and image—used by the host application (e.g., for display on a main screen summary of available modules). It does not contain business logic but serves as a wiring layer for UI composition.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 2. Public Interface
|
|||
|
|
|
|||
|
|
#### `HamburgerMenuModule` class
|
|||
|
|
- **`HamburgerMenuModule(IUnityContainer unityContainer)`**
|
|||
|
|
Constructor. Accepts a Unity container via dependency injection and stores it for later use in type registration.
|
|||
|
|
|
|||
|
|
- **`void Initialize()`**
|
|||
|
|
Registers two types as singletons in the Unity container:
|
|||
|
|
- `IHamburgerMenuView` → `HamburgerMenuView`
|
|||
|
|
- `IHamburgerMenuViewModel` → `HamburgerMenuViewModel`
|
|||
|
|
Uses `ContainerControlledLifetimeManager` to enforce singleton lifetime.
|
|||
|
|
|
|||
|
|
- **`void OnInitialized(IContainerProvider containerProvider)`**
|
|||
|
|
Currently empty. No initialization logic beyond `Initialize()` is performed here.
|
|||
|
|
|
|||
|
|
- **`void RegisterTypes(IContainerRegistry containerRegistry)`**
|
|||
|
|
Delegates to `Initialize()`. (Note: `IContainerRegistry` is Prism’s abstraction; however, this implementation ignores it and uses the injected `IUnityContainer` directly.)
|
|||
|
|
|
|||
|
|
#### `HamburgerMenuModuleNameAttribute` class
|
|||
|
|
- **`HamburgerMenuModuleNameAttribute()` / `HamburgerMenuModuleNameAttribute(string s)`**
|
|||
|
|
Constructor. Sets `AssemblyName` to `AssemblyNames.HamburgerMenu.ToString()` (value inferred from `DTS.Common.Interface.Menu.HamburgerMenu` namespace usage).
|
|||
|
|
|
|||
|
|
- **`string AssemblyName { get; }`**
|
|||
|
|
Returns `"HamburgerMenu"` (value of `AssemblyNames.HamburgerMenu.ToString()`).
|
|||
|
|
|
|||
|
|
- **`Type GetAttributeType()`**
|
|||
|
|
Returns `typeof(TextAttribute)`.
|
|||
|
|
|
|||
|
|
- **`string GetAssemblyName()`**
|
|||
|
|
Returns `AssemblyName`.
|
|||
|
|
|
|||
|
|
#### `HamburgerMenuModuleImageAttribute` class
|
|||
|
|
- **`HamburgerMenuModuleImageAttribute()` / `HamburgerMenuModuleImageAttribute(string s)`**
|
|||
|
|
Constructor. Loads the assembly image via `AssemblyInfo.GetImage("HamburgerMenu")`.
|
|||
|
|
|
|||
|
|
- **`BitmapImage AssemblyImage { get; }`**
|
|||
|
|
Returns the image loaded by `AssemblyInfo.GetImage("HamburgerMenu")`.
|
|||
|
|
|
|||
|
|
- **`string AssemblyName { get; }`**
|
|||
|
|
Returns `"HamburgerMenu"`.
|
|||
|
|
|
|||
|
|
- **`string AssemblyGroup { get; }`**
|
|||
|
|
Returns `"Prepare"` (value of `eAssemblyGroups.Prepare.ToString()`).
|
|||
|
|
|
|||
|
|
- **`eAssemblyRegion AssemblyRegion { get; }`**
|
|||
|
|
Returns `eAssemblyRegion.HamburgerMenuRegion`.
|
|||
|
|
|
|||
|
|
- **`Type GetAttributeType()`**
|
|||
|
|
Returns `typeof(ImageAttribute)`.
|
|||
|
|
|
|||
|
|
- **`BitmapImage GetAssemblyImage()`**
|
|||
|
|
Returns `AssemblyImage`.
|
|||
|
|
|
|||
|
|
- **`string GetAssemblyName()`**
|
|||
|
|
Returns `AssemblyName`.
|
|||
|
|
|
|||
|
|
- **`string GetAssemblyGroup()`**
|
|||
|
|
Returns `AssemblyGroup`.
|
|||
|
|
|
|||
|
|
- **`eAssemblyRegion GetAssemblyRegion()`**
|
|||
|
|
Returns `AssemblyRegion`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 3. Invariants
|
|||
|
|
- The module **must** be loaded after `DTS.Common` and `HamburgerMenu` assemblies are available (since it references `AssemblyNames.HamburgerMenu`, `AssemblyInfo`, `eAssemblyGroups`, and `eAssemblyRegion` from those).
|
|||
|
|
- `IHamburgerMenuView` and `IHamburgerMenuViewModel` are registered as **singleton** instances; multiple resolutions return the same instance.
|
|||
|
|
- The `AssemblyName` exposed via attributes is strictly `"HamburgerMenu"`.
|
|||
|
|
- The `AssemblyGroup` is fixed to `"Prepare"`.
|
|||
|
|
- The `AssemblyRegion` is fixed to `eAssemblyRegion.HamburgerMenuRegion`.
|
|||
|
|
- The image is loaded once per attribute instance (via `AssemblyInfo.GetImage`) and cached in `_img`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 4. Dependencies
|
|||
|
|
|
|||
|
|
#### This module depends on:
|
|||
|
|
- **Prism.Modularity** (`IModule`, `IContainerRegistry`, `IContainerProvider`)
|
|||
|
|
- **Unity** (`IUnityContainer`, `Unity.Lifetime.ContainerControlledLifetimeManager`)
|
|||
|
|
- **System.ComponentModel.Composition** (`[Export]`, `[Module]`)
|
|||
|
|
- **System.Windows.Media.Imaging** (`BitmapImage`)
|
|||
|
|
- **DTS.Common** (specifically `AssemblyNames`, `AssemblyInfo`, `eAssemblyGroups`, `eAssemblyRegion`)
|
|||
|
|
- **DTS.Common.Interface.Menu.HamburgerMenu** (specifically `IHamburgerMenuView`, `IHamburgerMenuViewModel`)
|
|||
|
|
- **Prism.Ioc** (`IContainerRegistry`, `IContainerProvider`)
|
|||
|
|
|
|||
|
|
#### This module is depended upon by:
|
|||
|
|
- The host application’s shell (e.g., `MainWindow.xaml` or a region manager) that resolves `IHamburgerMenuView` or uses the module’s metadata (via attributes) to display the hamburger menu component in the UI.
|
|||
|
|
- Any module or service that needs to inject `IHamburgerMenuView` or `IHamburgerMenuViewModel`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 5. Gotchas
|
|||
|
|
- **`RegisterTypes` ignores `IContainerRegistry`**: Though `RegisterTypes` receives a `IContainerRegistry`, it calls `Initialize()`, which uses the injected `IUnityContainer`. This tightly couples the module to Unity and breaks Prism’s container-agnostic design.
|
|||
|
|
- **Redundant `OnInitialized` implementation**: The `OnInitialized` method is empty and unused; no post-registration logic is performed.
|
|||
|
|
- **Attribute metadata is static**: `AssemblyImage`, `AssemblyName`, `AssemblyGroup`, and `AssemblyRegion` are computed once per attribute instance (in constructor or property getter), but not cached at the assembly level—repeated attribute usage may cause redundant `AssemblyInfo.GetImage` calls.
|
|||
|
|
- **No error handling for image loading**: If `AssemblyInfo.GetImage("HamburgerMenu")` fails (e.g., missing resource), the exception propagates during attribute instantiation (e.g., at assembly load time), potentially breaking module discovery.
|
|||
|
|
- **Missing documentation for `TextAttribute`/`ImageAttribute` base classes**: Their behavior (e.g., how `GetAttributeType()` is used) is not inferable from this source.
|
|||
|
|
- **No validation of `IHamburgerMenuView`/`IHamburgerMenuViewModel` implementations**: Assumes they exist and are compatible with the DI container.
|
|||
|
|
|
|||
|
|
None identified beyond the above.
|