Class EntityIdentifierCommand<TKey, TResponse>
- Namespace
- Arbiter.CommandQuery.Commands
- Assembly
- Arbiter.CommandQuery.dll
Represents a base command for operations that require an identifier.
public abstract record EntityIdentifierCommand<TKey, TResponse> : PrincipalCommandBase<TResponse>, IRequest<TResponse>, IRequest, IEquatable<PrincipalCommandBase<TResponse>>, IEquatable<EntityIdentifierCommand<TKey, TResponse>>
Type Parameters
TKey
The type of the key used to identify the entity.
TResponse
The type of the response returned by the command.
- Inheritance
-
PrincipalCommandBase<TResponse>EntityIdentifierCommand<TKey, TResponse>
- Implements
-
IRequest<TResponse>IEquatable<PrincipalCommandBase<TResponse>>IEquatable<EntityIdentifierCommand<TKey, TResponse>>
- Derived
- Inherited Members
Examples
The following example demonstrates how to use the EntityIdentifierCommand<TKey, TResponse>:
public record GetEntityByIdCommand : EntityIdentifierCommand<int, ProductReadModel>
{
public GetEntityByIdCommand(ClaimsPrincipal principal, int id)
: base(principal, id)
{
}
}
var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var command = new GetEntityByIdCommand(principal, 123);
// Pass the command to a handler or mediator
var result = await mediator.Send(command);
Console.WriteLine($"Entity Name: {result?.Name}");
Remarks
This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands that operate on a specific entity identified by a key.
Constructors
EntityIdentifierCommand(ClaimsPrincipal?, TKey)
Initializes a new instance of the EntityIdentifierCommand<TKey, TResponse> class.
protected EntityIdentifierCommand(ClaimsPrincipal? principal, TKey id)
Parameters
principal
ClaimsPrincipalThe ClaimsPrincipal representing the user executing the command.
id
TKeyThe identifier of the entity for this command.
Exceptions
- ArgumentNullException
Thrown when
id
is null.
Properties
Id
Gets the identifier for this command.
[JsonPropertyName("id")]
public TKey Id { get; }
Property Value
- TKey
The identifier of the entity for this command.