Table of Contents

Class ResourceAuthorizationPathResolver

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

Resolves a ResolvedAuthorizationPath from a leaf resource type to an owner resource type by walking the entity graph defined by IIdentifyRelatedResource<TRelated, TId> and IIdentifyRelatedResources<TRelated, TId> declarations on candidate entity types.

public static class ResourceAuthorizationPathResolver
Inheritance
ResourceAuthorizationPathResolver
Inherited Members

Remarks

Resolution rules:

  • Distinct simple paths. The resolver enumerates all simple paths (no node visited twice on the same path) from leafType to ownerType. Cycles in the entity graph are tolerated; only the cycle-free continuation matters.
  • Zero paths → InvalidOperationException at resolve time.
  • More than one path → InvalidOperationException at resolve time, listing all discovered paths. Disambiguate by removing an IIdentifyRelatedResource[s] declaration, by changing the command's TOwner, or by dropping to IResourceLoader<TMessage, TProjection> for a custom shape.
  • Exactly one path → the resolver builds typed extractor and loader delegates and wraps them in a ResolvedAuthorizationPath. Plural-middle is rejected by the path constructor; the resolver surfaces a clearer message.

The resolver uses reflection to enumerate interface declarations and to construct typed delegates. It is not AOT-safe; consumers targeting Native AOT should use an explicit registration helper instead — see ServiceCollectionExtensions.AddRelatedResourceAuthorization<TMessage, TLeaf, TLeafId, TOwner, TOwnerId, TResponse>(extractOwnerId) for the single-hop case or ServiceCollectionExtensions.AddRelatedResourceAuthorization<TMessage, TLeaf, TOwner, TResponse>(path) when accepting a hand-built path.

Methods

Resolve(Type, Type, Type, IReadOnlyCollection<Type>)

Resolves the authorization path for a command type from leaf to owner.

[RequiresUnreferencedCode("Walks IIdentifyRelatedResource[s] interfaces by reflection.")]
[RequiresDynamicCode("Constructs typed delegates via MakeGenericMethod.")]
public static ResolvedAuthorizationPath Resolve(Type messageType, Type leafType, Type ownerType, IReadOnlyCollection<Type> candidateEntityTypes)

Parameters

messageType Type

The command/query type that implements IAuthorizeResourceVia<TOwner>.

leafType Type

The leaf resource type the command identifies.

ownerType Type

The owner resource type authorization is evaluated against.

candidateEntityTypes IReadOnlyCollection<Type>

The set of concrete entity types to scan for IIdentifyRelatedResource<TRelated, TId> and IIdentifyRelatedResources<TRelated, TId> declarations. Typically the types in the assemblies passed to ServiceCollectionExtensions scanning.

Returns

ResolvedAuthorizationPath

The single resolved path.

Exceptions

ArgumentNullException

Thrown when any argument is null.

InvalidOperationException

Thrown when no path exists, multiple distinct simple paths exist, or a plural hop appears in a non-terminal position on the resolved path.