Skip to content

Compono.GeneratedTestDoubleRegistry

Compono

Compono

GeneratedTestDoubleRegistry Class

A System.Type-keyed registry of factories for generator-emitted test doubles, populated by a generated [ModuleInitializer] per discovered interface (never by Compono itself), the same cross-assembly-population shape as RowInvokerRegistry. Read by Compono.TestDoubles's GeneratedTestDoubleProvider - core Compono has no reference the other way. See ADR-0043 Amendment 2.

public static class GeneratedTestDoubleRegistry

Inheritance System.Object → GeneratedTestDoubleRegistry

Remarks

Unlike RowInvokerRegistry, whose duplicate registrations for the same System.Type are genuinely interchangeable, two different assemblies generating a double for the same shared interface produce two distinct, non-interchangeable concrete types. RegisterFactory<T>(Func<T>) is still first-registration-wins (via System.Collections.Concurrent.ConcurrentDictionary<>.GetOrAdd(@0,@1), deterministic, never a throw or blind overwrite) - a documented v1 limitation for the multi-assembly-same-interface scenario, not a bug: the generated Configure() bridge's cast-failure message names this exact scenario so a consumer who hits it understands why. See ADR-0043 Amendment 3, Finding C.

Every entry stored here permanently roots its registered factory delegate (and the generating assembly) for the process's lifetime - the same collectible-System.Runtime.Loader.AssemblyLoadContext-rooting consequence already documented for RowInvokerRegistry. See ADR-0043 Amendment 5, Finding M, and docs/architecture/current/generated-plans-and-discovery.md's "Open questions" section (Phase 3 doc task).

Methods
RegisterFactory<T>(Func<T>) Idempotently registers factory for T - a second registration for a T already present (e.g. from another assembly's own generated module initializer) is a no-op, never a throw or an overwrite.
TryCreate(Type, object) Looks up and invokes the factory registered for requestedType, or false if none has been registered - either because requestedType was never discovered as a generated-test-double leaf, or because the consuming assembly's module initializers haven't run yet.