Files
DP44/enriched-partialglm/Common/DTS.CommonCore/ModuleCatalog.md

66 lines
4.7 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- Common/DTS.CommonCore/ModuleCatalog/AggregateModuleCatalog.cs
generated_at: "2026-04-16T12:02:00.610314+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "6c5b3cbd6c5102fe"
---
# Documentation: AggregateModuleCatalog
## 1. Purpose
The `AggregateModuleCatalog` class provides a composite implementation of the Prism `IModuleCatalog` interface. It allows the application to combine multiple distinct module catalogs (e.g., a `DirectoryModuleCatalog`, a `ModuleCatalog`, etc.) into a single logical unit. This enables modules to be discovered and loaded from heterogeneous sources simultaneously while presenting a unified interface to the module management system.
## 2. Public Interface
* **`AggregateModuleCatalog()`**
* **Signature:** `public AggregateModuleCatalog()`
* **Behavior:** Initializes a new instance of the class. It pre-populates the internal list of catalogs with a default instance of `ModuleCatalog` (located at index 0).
* **`AddCatalog(IModuleCatalog catalog)`**
* **Signature:** `public void AddCatalog(IModuleCatalog catalog)`
* **Behavior:** Adds a specific `IModuleCatalog` instance to the aggregate collection.
* **Validation:** Throws `ArgumentNullException` if the provided `catalog` is null.
* **`Modules`**
* **Signature:** `public IEnumerable<ModuleInfo> Modules { get; }`
* **Behavior:** Aggregates and returns the `ModuleInfo` objects from all catalogs currently held in the collection.
* **`GetDependentModules(ModuleInfo moduleInfo)`**
* **Signature:** `public IEnumerable<ModuleInfo> GetDependentModules(ModuleInfo moduleInfo)`
* **Behavior:** Locates the specific catalog that contains the provided `moduleInfo` and delegates the call to that catalog's `GetDependentModules` method.
* **`CompleteListWithDependencies(IEnumerable<ModuleInfo> modules)`**
* **Signature:** `public IEnumerable<ModuleInfo> CompleteListWithDependencies(IEnumerable<ModuleInfo> modules)`
* **Behavior:** Groups the provided modules by their owning catalog and calls `CompleteListWithDependencies` on each respective catalog, returning the combined result.
* **`Initialize()`**
* **Signature:** `public void Initialize()`
* **Behavior:** Iterates through all catalogs in the collection and calls their `Initialize()` method.
* **`AddModule(ModuleInfo moduleInfo)`**
* **Signature:** `public void AddModule(ModuleInfo moduleInfo)`
* **Behavior:** Adds the provided `moduleInfo` specifically to the first catalog in the internal list (`_catalogs[0]`), which is the default `ModuleCatalog` created in the constructor.
## 3. Invariants
* **Non-Empty Catalog List:** The internal `_catalogs` list is never empty. It is initialized with a default `ModuleCatalog` in the constructor.
* **Module Ownership:** A `ModuleInfo` instance must exist in exactly one of the aggregated catalogs for dependency resolution to succeed. The methods `GetDependentModules` and `CompleteListWithDependencies` rely on `_catalogs.Single(...)` logic to find the owner; if a module appears in multiple catalogs or no catalogs, the `Single` operation will throw an `InvalidOperationException`.
* **AddModule Target:** The `AddModule` method always targets the first catalog in the collection (index 0).
## 4. Dependencies
* **External Dependencies:**
* `Microsoft.Practices.Prism.Modularity`: The class implements `IModuleCatalog` and utilizes types `ModuleInfo` and `ModuleCatalog`.
* **Standard Libraries:**
* `System`
* `System.Collections.Generic`
* `System.Linq`
## 5. Gotchas
* **Hardcoded AddModule Behavior:** Calling `AddModule` does not add the module to the "aggregate" generally; it specifically adds it to the default `ModuleCatalog` stored at `_catalogs[0]`. If a developer adds a new catalog via `AddCatalog` and expects `AddModule` to interact with that new catalog, they will be mistaken.
* **Strict Uniqueness Constraint:** The dependency resolution methods use `System.Linq.Single` to locate the catalog owning a specific module. If the same `ModuleInfo` instance (or equivalent identity) is added to multiple sub-catalogs, the application will crash during dependency resolution because `Single` expects exactly one match.
* **Commented-Out Validation Logic:** The `AddCatalog` method contains a large block of commented-out code attempting to validate `DirectoryModuleCatalog` paths. This suggests unfinished validation logic or technical debt regarding duplicate directory paths that was abandoned.
* **Exception Message Typo:** In `AddCatalog`, the `ArgumentNullException` is instantiated with a string literal `$"catalog"` using string interpolation unnecessarily. While functional, it deviates from standard practices (usually `nameof(catalog)`).