Table of Contents

Class SharedResourceLoaderById<TResource, TId>

Namespace
Trellis.Authorization
Assembly
Trellis.Authorization.dll

Shared resource loader that loads a resource by ID. Register one per resource type instead of one ResourceLoaderById<TMessage, TResource, TId> per command.

public abstract class SharedResourceLoaderById<TResource, TId>

Type Parameters

TResource

The aggregate or entity type to load.

TId

The identifier type (e.g., OrderId).

Inheritance
SharedResourceLoaderById<TResource, TId>
Derived
Inherited Members
Extension Methods

Examples

// ONE class serves ALL commands that authorize against Order
public sealed class OrderResourceLoader(IOrderRepository repo)
    : SharedResourceLoaderById<Order, OrderId>
{
    public override Task<Result<Order>> GetByIdAsync(OrderId id, CancellationToken ct)
        => repo.GetByIdAsync(id, ct);
}

Remarks

When a command implements both IAuthorizeResource<TResource> and IIdentifyResource<TResource, TId>, the pipeline automatically bridges to this shared loader — no per-command loader class needed.

Explicit IResourceLoader<TMessage, TResource> registrations always take priority over the shared loader.

Methods

GetByIdAsync(TId, CancellationToken)

Loads the resource by ID. Return Result.Failure with a NotFoundError if the resource does not exist.

public abstract Task<Result<TResource>> GetByIdAsync(TId id, CancellationToken cancellationToken)

Parameters

id TId

The resource identifier.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<TResource>>

A success result containing the loaded resource, or a failure result if not found.