Table of Contents

Class EntityModelCommand<TEntityModel, TReadModel>

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

Represents a base command that uses a view model to perform an operation.

public abstract record EntityModelCommand<TEntityModel, TReadModel> : PrincipalCommandBase<TReadModel>, IRequest<TReadModel>, IRequest, IEquatable<PrincipalCommandBase<TReadModel>>, IEquatable<EntityModelCommand<TEntityModel, TReadModel>>

Type Parameters

TEntityModel

The type of the model used as input for the command.

TReadModel

The type of the read model returned as the result of the command.

Inheritance
EntityModelCommand<TEntityModel, TReadModel>
Implements
IRequest<TReadModel>
IEquatable<EntityModelCommand<TEntityModel, TReadModel>>
Derived
Inherited Members

Examples

The following example demonstrates how to use the EntityModelCommand<TEntityModel, TReadModel>:

public record CreateProductCommand : EntityModelCommand<ProductCreateModel, ProductReadModel>
{
    public CreateProductCommand(ClaimsPrincipal principal, ProductCreateModel model)
        : base(principal, model)
    {
    }
}

var createModel = new ProductCreateModel
{
    Name = "New Product",
    Description = "A description of the new product",
    Price = 19.99m
};

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

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

Remarks

This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands that operate on an entity using a model and return a read model as the result.

Constructors

EntityModelCommand(ClaimsPrincipal?, TEntityModel)

Initializes a new instance of the EntityModelCommand<TEntityModel, TReadModel> class.

protected EntityModelCommand(ClaimsPrincipal? principal, TEntityModel model)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the command.

model TEntityModel

The model containing the data for the operation.

Exceptions

ArgumentNullException

Thrown when model is null.

Properties

Model

Gets the view model used for this command.

[JsonPropertyName("model")]
public TEntityModel Model { get; }

Property Value

TEntityModel

The view model containing the data for the operation.