Skip to main content
Table of Contents

Interface ITrustedTypeResolver

Namespace
Stratara.Abstractions.Reflections
Assembly
Stratara.Abstractions.dll

Resolves runtime Type instances from persisted type-name strings against a host-defined allowlist. The framework uses this in code paths that deserialize messages arriving from message buses or event-store rows, where a naive GetType(string) against attacker-controlled input would permit instantiation of arbitrary public types loaded into the process.

public interface ITrustedTypeResolver
Extension Methods

Remarks

Population happens at startup through the DI scan extensions ( AddCommandHandlersFromAssemblyContaining<T>, AddProjectionsFromAssemblyContaining<T>, AddSagasFromAssemblyContaining<T>, AddAggregatesFromAssemblyContaining<T>). Each scan registers the relevant command / event / aggregate types into the resolver. Hosts may also register additional types explicitly via services.AddTrustedType<T>() for types that are produced but never directly handled (e.g. aggregate snapshot types whose aggregates have no projection / saga).

Unregistered type names are rejected with InvalidOperationException. The resolver normalises the assembly-qualified name to its version-independent form (no Version= / Culture= / PublicKeyToken= tokens) before lookup so events written by a previous package version still resolve after a consumer upgrade.

Properties

RegisteredTypes

Snapshot of every type currently registered with the resolver.

IReadOnlyCollection<Type> RegisteredTypes { get; }

Property Value

IReadOnlyCollection<Type>

Remarks

Returned collection is a point-in-time snapshot — concurrent Register(Type) calls after iteration begins are not reflected. Startup validators (for example the encryption metadata drift guard) use this to walk the full allowlist once at host start.

Methods

Register(Type)

Registers type in the resolver. Registering the same type again is a no-op; registering a different type under a name already taken is rejected rather than discarded, so a name clash surfaces at registration instead of silently resolving to whichever type won.

void Register(Type type)

Parameters

type Type

The type to register.

Exceptions

ArgumentNullException

type is null.

InvalidOperationException

type has no assembly-qualified name, or a different type is already registered under the same version-independent name.

Resolve(string)

Returns the Type matching typeName or throws InvalidOperationException.

Type Resolve(string typeName)

Parameters

typeName string

Assembly-qualified or version-independent type name as persisted with the event / command / aggregate row.

Returns

Type

The registered runtime type.

Exceptions

ArgumentNullException

typeName is null.

InvalidOperationException

No type matching typeName has been registered.

TryResolve(string, out Type?)

Attempts to resolve typeName without throwing.

bool TryResolve(string typeName, out Type? type)

Parameters

typeName string

Assembly-qualified or version-independent type name.

type Type

Receives the resolved type on success; null on failure.

Returns

bool

true if a registered type matched; false otherwise.