Interface IResourceLoader<TMessage, TResource>
- Namespace
- Trellis.Authorization
- Assembly
- Trellis.Authorization.dll
Loads the resource required for resource-based authorization. Registered in DI as scoped (typically depends on DbContext via a repository). Resolved per-request by the pipeline behavior via IServiceProvider.
public interface IResourceLoader<in TMessage, TResource>
Type Parameters
TMessageThe command or query type that triggers the resource load.
TResourceThe type of resource to load.
- Extension Methods
Remarks
Implement this interface directly when the loading logic is complex (e.g., composite keys, joins, or projections). For the common case of extracting an ID and calling a repository, use ResourceLoaderById<TMessage, TResource, TId>.
Methods
LoadAsync(TMessage, CancellationToken)
Loads the resource identified by the message.
Task<Result<TResource>> LoadAsync(TMessage message, CancellationToken cancellationToken)
Parameters
messageTMessageThe command or query containing the resource identifier.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<Result<TResource>>
A success result containing the loaded resource, or a failure result (typically NotFound(string, string?)) if the resource does not exist.