Files
2026-04-17 14:55:32 -04:00

6.7 KiB
Raw Permalink Blame History

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/Modules/SystemSettings/TestSettings/TestSettingsModule.cs
2026-04-16T04:40:08.753716+00:00 Qwen/Qwen3-Coder-Next-FP8 1 30e4791dc9f8aa59

TestSettings

Documentation: TestSettingsModule and TestSettingsImageAttribute


1. Purpose

This module (TestSettingsModule) is a Prism modularity module responsible for registering the Test Settings UI component (View and ViewModel) into the Unity dependency injection container as singletons, enabling its later resolution and use within the application. It is part of the TestSettings assembly and integrates with the larger Prism-based application shell. The TestSettingsImageAttribute class provides metadata (image and name) for the assembly, used by the main UI to display the component in a component list or dashboard. The module does not perform runtime initialization logic beyond registration; all initialization is deferred to the container resolution of its types.


2. Public Interface

TestSettingsModule class

  • TestSettingsModule(IUnityContainer unityContainer)
    Constructor. Accepts a Unity container via dependency injection and stores it for later use in type registration.

  • void Initialize()
    Registers two types with the Unity container as transient (default Unity behavior unless otherwise specified):

    • ITestSettingsViewTestSettingsView
    • ITestSettingsViewModelTestSettingsViewModel
      Note: The source does not explicitly specify singleton lifetime — Unitys default registration is transient unless .Singleton() is used. However, the XML comment says “singleton” — this is inconsistent with the code and likely an error or documentation artifact.
  • void OnInitialized(IContainerProvider containerProvider)
    Empty implementation. No logic executed during Prisms OnInitialized pipeline.

  • void RegisterTypes(IContainerRegistry containerRegistry)
    Delegates to Initialize() — effectively re-runs the same type registrations. Note: This method receives a Prism IContainerRegistry, but internally uses the stored _unityContainer (of type IUnityContainer) instead of containerRegistry. This is likely unintended and may cause registration to fail or be inconsistent depending on how Prism wraps Unity.

TestSettingsImageAttribute class

  • TestSettingsImageAttribute()
    Default constructor; delegates to the parameterized constructor with null.

  • TestSettingsImageAttribute(string s)
    Constructor that initializes _img by calling AssemblyInfo.GetImage(AssemblyNames.TestSettings.ToString()).

  • override eAssemblyRegion AssemblyRegion
    Property that always throws NotImplementedException. Not functional.

  • override BitmapImage AssemblyImage
    Property that returns the result of AssemblyInfo.GetImage(AssemblyNames.TestSettings.ToString()). Cached in _img on first access.

  • override Type GetAttributeType()
    Returns typeof(ImageAttribute).

  • override BitmapImage GetAssemblyImage()
    Returns the value of AssemblyImage.

  • override string AssemblyName
    Property that returns "TestSettings" (via AssemblyNames.TestSettings.ToString()). Cached in _name.

  • override string GetAssemblyName()
    Returns the value of AssemblyName.

  • override eAssemblyRegion GetAssemblyRegion()
    Always throws NotImplementedException. Not functional.

  • override string AssemblyGroup
    Property that returns "Administrative" (via eAssemblyGroups.Administrative.ToString()). Cached in _group.

  • override string GetAssemblyGroup()
    Returns the value of AssemblyGroup.


3. Invariants

  • TestSettingsModule must be instantiated with a valid IUnityContainer instance; otherwise, Initialize() will throw NullReferenceException.
  • AssemblyInfo.GetImage(...) and AssemblyNames.TestSettings must be defined and accessible at runtime; otherwise, TestSettingsImageAttribute constructors and property getters will throw exceptions (e.g., NullReferenceException, KeyNotFoundException, or custom exceptions from AssemblyInfo).
  • AssemblyRegion and GetAssemblyRegion() are non-functional — any consumer relying on them will crash. This is a hard invariant failure point.
  • AssemblyGroup is hardcoded to "Administrative" — no runtime variability is supported.

4. Dependencies

This module depends on:

  • Unity (IUnityContainer)
  • Prism.Modularity (IModule, ModuleAttribute)
  • Prism.Ioc (IContainerProvider, IContainerRegistry)
  • DTS.Common (specifically AssemblyInfo, AssemblyNames, eAssemblyGroups, ImageAttribute)
  • System.Windows.Media.Imaging (BitmapImage)
  • System.ComponentModel.Composition (ExportAttribute)

This module is depended on by:

  • The Prism bootstrapper/module catalog — via [Export(typeof(IModule))] and [Module(ModuleName = "TestSettings")], it is auto-discovered and loaded as a module named "TestSettings".
  • Any UI component that resolves ITestSettingsView or ITestSettingsViewModel via the Unity container.
  • The main shell/application — via TestSettingsImageAttribute (likely applied at assembly level), used to render UI for this module (e.g., in a module list or dashboard).

5. Gotchas

  • Critical inconsistency in RegisterTypes: The method receives IContainerRegistry, but internally calls Initialize(), which uses _unityContainer (IUnityContainer). This likely means registrations are performed on the wrong container (or the wrong container is passed in), potentially causing runtime resolution failures. This is a high-risk bug.
  • AssemblyRegion and GetAssemblyRegion() are unimplemented — always throw NotImplementedException. Any code expecting these to return a valid region (e.g., for categorization) will crash.
  • XML comment claims singleton registration, but code does not enforce it — Unity registers types as transient by default. If a singleton is required, .Singleton() must be explicitly used (e.g., _unityContainer.RegisterType<ITestSettingsView, TestSettingsView>(new ContainerControlledLifetimeManager())). This mismatch is a likely source of bugs.
  • TestSettingsImageAttribute constructor parameter string s is unused — it is accepted but never assigned or used.
  • No validation or error handling — e.g., if AssemblyInfo.GetImage(...) returns null, the property getter will propagate null, potentially causing downstream rendering issues (e.g., missing icons).
  • AssemblyGroup is hardcoded — not configurable or data-driven, limiting flexibility.

None identified beyond the above.