Class ResourceAuthorizationPathResolver
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
leafTypetoownerType. 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'sTOwner, or by dropping toIResourceLoader<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
messageTypeTypeThe command/query type that implements IAuthorizeResourceVia<TOwner>.
leafTypeTypeThe leaf resource type the command identifies.
ownerTypeTypeThe owner resource type authorization is evaluated against.
candidateEntityTypesIReadOnlyCollection<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.