// CQRS
// Command
// Query
// Responsibility Segregation
// command
public record RegisterProduct;
// query
public record GetProductDetails;
interface ICommandHandler<in TCommand>
{
ValueTask Handle(TCommand command, CancellationToken ct);
}
interface IQueryHandler<in TQuery, TResult>
{
ValueTask<TResult> Handle(TQuery query, CancellationToken ct);
}
COMMAND
record RegisterProduct(
Guid ProductId,
string Sku,
string Name,
string? Description = null
);
Create
var registerProduct = new RegisterProduct(
Guid.NewGuid(),
"CC2029384",
"Bricks"
);
Immutability
registerProduct.ProductId = Guid.NewGuid();
Nullability
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
var registerProduct = new RegisterProduct(
Guid.NewGuid(),
"CC2029384",
null
);
var registerProduct2 = RegisterProduct.Create(
Guid.NewGuid(),
"CC2029384",
null!
);
record RegisterProduct
{
public Guid ProductId { get; init; }
public string SKU { get; init; }
public string Name { get; init; }
public string? Description { get; init; }
public RegisterProduct(Guid productId, string sku, string name, string? description= null)
{
ProductId = productId;
SKU = sku;
Name = name;
Description = description;
}