5.9 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T02:54:14.695851+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 7afb65b5d3f17781 |
ModuleCatalog
Purpose
The AggregateModuleCatalog class serves as a composite wrapper around multiple IModuleCatalog instances, enabling modular module discovery and management across heterogeneous sources (e.g., configuration files, assemblies, or dynamic catalogs) within the Prism-based module loading framework. It consolidates module definitions from its constituent catalogs into a unified interface while delegating core operations—such as dependency resolution, initialization, and module enumeration—to the underlying catalogs. Its primary role is to support extensibility by allowing additional catalogs to be added at runtime, while maintaining a single entry point for module catalog operations.
Public Interface
-
AggregateModuleCatalog()
Constructor. Initializes a new instance with a defaultModuleCatalog(stored as the first element in_catalogs). This default catalog is used for modules added viaAddModule(ModuleInfo). -
void AddCatalog(IModuleCatalog catalog)
Appends a newIModuleCataloginstance to the internal list of catalogs. ThrowsArgumentNullExceptionifcatalogisnull. -
IEnumerable<ModuleInfo> Modules { get; }
Returns a flattened enumeration of allModuleInfoinstances across all contained catalogs, viaSelectMany. -
IEnumerable<ModuleInfo> GetDependentModules(ModuleInfo moduleInfo)
Locates the single catalog containingmoduleInfo(viaSingle(x => x.Modules.Contains(moduleInfo))) and delegates the call to that catalog. Returns the module’s dependencies as reported by the underlying catalog. -
IEnumerable<ModuleInfo> CompleteListWithDependencies(IEnumerable<ModuleInfo> modules)
Groups the inputmodulesby their source catalog (again usingSingle(...)to identify the catalog), then delegatesCompleteListWithDependenciesper catalog. Returns the union of all dependency-expanded module sets. -
void Initialize()
InvokesInitialize()on each catalog in_catalogs, enabling initialization logic (e.g., loading, validation) across all catalogs. -
void AddModule(ModuleInfo moduleInfo)
AddsmoduleInfoexclusively to the first catalog in_catalogs(i.e., the defaultModuleCatalogcreated in the constructor). Does not attempt to distribute modules across catalogs.
Invariants
-
Catalog Membership Uniqueness:
GetDependentModulesandCompleteListWithDependenciesassume exactly one catalog in_catalogscontains a givenModuleInfo. If aModuleInfoappears in multiple catalogs,Single(...)will throwInvalidOperationException.
→ This implies modules must be unique across all constituent catalogs. -
Default Catalog Preservation:
The first catalog (_catalogs[0]) is always the initialModuleCataloginstance created in the constructor. It is never removed or replaced. -
Module Addition Target:
All modules added viaAddModule(ModuleInfo)are placed in_catalogs[0]. Modules added viaAddCatalogmay reside in any catalog, but must not duplicate modules already in_catalogs[0](to satisfy uniqueness). -
Catalog Initialization Order:
Initialize()calls each catalog’sInitialize()in the order they appear in_catalogs. No ordering guarantees beyond this sequence are specified.
Dependencies
-
Depends on:
Microsoft.Practices.Prism.Modularity(specifically, theIModuleCatalogandModuleInfotypes).System,System.Collections.Generic,System.Linq(for LINQ operations likeSelectMany,GroupBy,Single).
-
Depended on by:
- Inferred from namespace (
DTS.Common) and class name: likely consumed by Prism-based module initialization logic (e.g.,ModuleManagerorModuleInitializerfrom Prism), though not explicit in the source. - No direct usage is visible in this file, but as an
IModuleCatalogimplementation, it is intended for integration with Prism’s module loading pipeline.
- Inferred from namespace (
Gotchas
-
Fragile Catalog Lookup via
Single(...):
GetDependentModulesandCompleteListWithDependenciesuseSingle(x => x.Modules.Contains(moduleInfo)), which:- Fails if a
ModuleInfoexists in multiple catalogs (throwsInvalidOperationException). - Fails if a
ModuleInfois not found in any catalog (also throwsInvalidOperationException).
→ This is a critical reliability risk if catalogs overlap or modules are added inconsistently.
- Fails if a
-
Asymmetric
AddModuleBehavior:
AddModuleonly adds to the first catalog (_catalogs[0]). Users might expect modules to be distributed or added to a specific catalog, leading to confusion if they add modules expecting them to appear in a custom catalog added viaAddCatalog. -
No Catalog Removal/Reordering Support:
There is no method to remove catalogs or change their order. The first catalog is fixed, and subsequent catalogs are appended. This limits flexibility in dynamic scenarios. -
No Validation of Catalog Compatibility:
The class does not enforce that catalogs use compatibleModuleInfoimplementations or metadata schemas. Inconsistent catalogs may cause runtime errors during dependency resolution. -
No Thread Safety:
The class is not marked thread-safe. Concurrent modifications (e.g.,AddCatalogduring enumeration) may cause exceptions. -
Assumes
Modules.ContainsIdentity Semantics:
Relies onIModuleCatalog.Modules.Contains(moduleInfo)to identify the source catalog. This assumesModuleInfoimplements value-based equality (e.g., viaEquals/GetHashCode), which may not hold ifModuleInfouses reference equality.