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
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
typeTypeThe type to register.
Exceptions
- ArgumentNullException
typeisnull.- InvalidOperationException
typehas 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
typeNamestringAssembly-qualified or version-independent type name as persisted with the event / command / aggregate row.
Returns
- Type
The registered runtime type.
Exceptions
- ArgumentNullException
typeNameisnull.- InvalidOperationException
No type matching
typeNamehas been registered.
TryResolve(string, out Type?)
Attempts to resolve typeName without throwing.
bool TryResolve(string typeName, out Type? type)
Parameters
typeNamestringAssembly-qualified or version-independent type name.
typeTypeReceives the resolved type on success;
nullon failure.
Returns
- bool
trueif a registered type matched;falseotherwise.