Table of Contents

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

TMessage

The command or query type that triggers the resource load.

TResource

The 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

message TMessage

The command or query containing the resource identifier.

cancellationToken CancellationToken

Cancellation 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.