Class EntityCreateCommand<TCreateModel, TReadModel>
- Namespace
- Arbiter.CommandQuery.Commands
- Assembly
- Arbiter.CommandQuery.dll
Represents a command to create a new entity using the specified TCreateModel
.
The result of the command will be of type TReadModel
.
public record EntityCreateCommand<TCreateModel, TReadModel> : EntityModelCommand<TCreateModel, TReadModel>, IRequest<TReadModel>, IRequest, IEquatable<PrincipalCommandBase<TReadModel>>, IEquatable<EntityModelCommand<TCreateModel, TReadModel>>, ICacheExpire, IEquatable<EntityCreateCommand<TCreateModel, TReadModel>>
Type Parameters
TCreateModel
The type of the create model used to provide data for the new entity.
TReadModel
The type of the read model returned as the result of the command.
- Inheritance
-
PrincipalCommandBase<TReadModel>EntityModelCommand<TCreateModel, TReadModel>EntityCreateCommand<TCreateModel, TReadModel>
- Implements
-
IRequest<TReadModel>IEquatable<PrincipalCommandBase<TReadModel>>IEquatable<EntityModelCommand<TCreateModel, TReadModel>>IEquatable<EntityCreateCommand<TCreateModel, TReadModel>>
- Inherited Members
Examples
The following example demonstrates how to use the EntityCreateCommand<TCreateModel, TReadModel>:
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 EntityCreateCommand<ProductCreateModel, ProductReadModel>(principal, createModel);
// Pass the command to the mediator for execution
var result = await mediator.Send(command);
Console.WriteLine($"Created product: {result?.Name}");
Remarks
This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to create a new entity and return a read model representing the created entity or a related result.
Constructors
EntityCreateCommand(ClaimsPrincipal?, TCreateModel)
Initializes a new instance of the EntityCreateCommand<TCreateModel, TReadModel> class.
public EntityCreateCommand(ClaimsPrincipal? principal, TCreateModel model)
Parameters
principal
ClaimsPrincipalThe ClaimsPrincipal representing the user for whom this command is executed.
model
TCreateModelThe create model containing the data for the new entity.
Exceptions
- ArgumentNullException
Thrown when
model
is null.