Command Query
Command Query Responsibility Segregation (CQRS) framework based on mediator pattern
Command Query Installation
The Arbiter Command Query library is available on nuget.org via package name Arbiter.CommandQuery.
To install Arbiter Command Query, run the following command in the Package Manager Console
Install-Package Arbiter.CommandQuery
OR
dotnet add package Arbiter.CommandQuery
Command Query Features
- Base commands and queries for common CRUD operations
- Generics base handlers for implementing common CRUD operations
- Common behaviors for audit, caching, soft delete, multi-tenant
- View model to data modal mapping
- Entity Framework Core handlers for common CRUD operations
- MongoDB handlers for common CRUD operations
Command Query Usage
Register Command Query services via dependency injection
services.AddCommandQuery();
Query By ID
// sample user claims
var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var query = new EntityIdentifierQuery<int, ProductReadModel>(principal, 123);
// Send the query to the mediator for execution
var result = await mediator.Send(query);
Query By Filter
var entityQuery = new EntityQuery
{
Filter = new EntityFilter { Name = "Status", Operator = FilterOperators.Equal, Value = "Active" },
Sort = new[] { new EntitySort { Name = "Name", Direction = SortDirections.Ascending } },
Page = 1,
PageSize = 20
};
var query = new EntityPagedQuery<ProductReadModel>(principal, entityQuery);
// Send the query to the mediator for execution
var pagedResult = await mediator.Send(query);
Update Command
var id = 123; // The ID of the entity to update
var updateModel = new ProductUpdateModel
{
Name = "Updated Product",
Description = "Updated description of the product",
Price = 29.99m
};
var command = new EntityUpdateCommand<int, ProductUpdateModel, ProductReadModel>(principal, id, updateModel);
// Send the command to the mediator for execution
var result = await mediator.Send(command);