Table of Contents

Class PrincipalCommandBase<TResponse>

Namespace
Arbiter.CommandQuery.Commands
Assembly
Arbiter.CommandQuery.dll

Represents a base command type that uses a specified ClaimsPrincipal to execute operations.

public abstract record PrincipalCommandBase<TResponse> : IRequest<TResponse>, IRequest, IEquatable<PrincipalCommandBase<TResponse>>

Type Parameters

TResponse

The type of the response returned by the command.

Inheritance
PrincipalCommandBase<TResponse>
Implements
IRequest<TResponse>
Derived
Inherited Members

Examples

The following example demonstrates how to use the PrincipalCommandBase<TResponse>:

public record GetUserDetailsCommand : PrincipalCommandBase<UserDetails>
{
    public GetUserDetailsCommand(ClaimsPrincipal principal) : base(principal)
    {
    }
}

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var command = new GetUserDetailsCommand(principal);

// Pass the command to a handler or mediator
var result = await mediator.Send(command);
Console.WriteLine($"User Name: {result?.Name}");

Remarks

This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands that require user context, such as authentication or authorization, provided by a ClaimsPrincipal.

Constructors

PrincipalCommandBase(ClaimsPrincipal?)

Initializes a new instance of the PrincipalCommandBase<TResponse> class.

protected PrincipalCommandBase(ClaimsPrincipal? principal)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the command.

Properties

Activated

Gets the timestamp indicating when this command was activated.

public DateTimeOffset Activated { get; }

Property Value

DateTimeOffset

The timestamp indicating when this command was activated.

ActivatedBy

Gets the user name of the individual who activated this command. Extracted from the specified Principal.

public string? ActivatedBy { get; }

Property Value

string

The user name of the individual who activated this command.

Remarks

If the Principal is null, the value defaults to "system".

Principal

Gets the ClaimsPrincipal representing the user executing the command.

[JsonPropertyName("principal")]
[JsonConverter(typeof(ClaimsPrincipalConverter))]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ClaimsPrincipal? Principal { get; }

Property Value

ClaimsPrincipal

The ClaimsPrincipal representing the user executing the command.