MSHelper.CQRS.Queries
1.0.0
dotnet add package MSHelper.CQRS.Queries --version 1.0.0
NuGet\Install-Package MSHelper.CQRS.Queries -Version 1.0.0
<PackageReference Include="MSHelper.CQRS.Queries" Version="1.0.0" />
paket add MSHelper.CQRS.Queries --version 1.0.0
#r "nuget: MSHelper.CQRS.Queries, 1.0.0"
// Install MSHelper.CQRS.Queries as a Cake Addin #addin nuget:?package=MSHelper.CQRS.Queries&version=1.0.0 // Install MSHelper.CQRS.Queries as a Cake Tool #tool nuget:?package=MSHelper.CQRS.Queries&version=1.0.0
MSHelper.CQRS.Queries : Queries
⭐ Star us on GitHub � it motivates us a lot!
Overview
Adds an ability to create and process queries in the sense of CQRS.
Installation
This document is for the latest MSHelper.CQRS.Queries 1.0.0 release and later.
dotnet add package MSHelper.CQRS.Queries
Dependencies
-- MSHelper
Usage
Implement IQuery<TResult>
interface in the selected class:
public class GetAccount : IQuery<AccountDto>
{
public Guid Id { get; set; }
}
Create dedicated query handler class that implements IQueryHandler<TQuery, TResult>
interface with HandleAsync()
method:
public class GetAccountHandler : IQueryHandler<GetAccount, AccountDto>
{
public Task<AccountDto> HandleAsync(GetAccount query)
{
//put the handling code here
}
}
You can easily register all query handlers in DI container by calling AddQueryHandlers()
method on IMSHelperBuilder
:
public IServiceProvider ConfigureServices(this IServiceCollection services)
{
var builder = services.AddMSHelper()
.AddQueryHandlers();
//other registrations
return builder.Build();
}
Dispatching a particular query object can be also done using MSHelper package. Start with registering in-memory dispatcher on your IMSHelperBuilder
by calling a AddInMemoryQueryDispatcher()
method:
public IServiceProvider ConfigureServices(this IServiceCollection services)
{
var builder = services.AddMSHelper()
.AddQueryHandlers()
.AddInMemoryQueryDispatcher();
//other registrations
return builder.Build();
}
Then simply inject IQueryDispatcher
into a class and call DispatchAsync()
method:
public class AccountsService
{
private readonly IQueryDispatcher _dispatcher;
public AccountsService(IQueryDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
public Task<AccountDto> GetAccountAsync(Guid id)
=> _dispatcher.DispatchAsync(new GetAccount { Id = id });
}
Important Note:
All the MSHelper packages are for self learning purposes inspired by Devmentors.io
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- MSHelper (>= 1.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MSHelper.CQRS.Queries:
Package | Downloads |
---|---|
MSHelper.Persistence.MongoDB
MSHelper.Persistence.MongoDB - Adds the set of conventions and ease of use for MongoDB integration with .NET Core. |
|
MSHelper.WebApi.CQRS
MSHelper.WebApi.CQRS - CQRS Integration. |
|
MSHelper.Logging.CQRS
MSHelper.Logging.CQRS - Centralized logging for CQRS with Serilog and Seq. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 361 | 10/25/2022 |