MSHelper.CQRS.Events
1.0.0
dotnet add package MSHelper.CQRS.Events --version 1.0.0
NuGet\Install-Package MSHelper.CQRS.Events -Version 1.0.0
<PackageReference Include="MSHelper.CQRS.Events" Version="1.0.0" />
paket add MSHelper.CQRS.Events --version 1.0.0
#r "nuget: MSHelper.CQRS.Events, 1.0.0"
// Install MSHelper.CQRS.Events as a Cake Addin #addin nuget:?package=MSHelper.CQRS.Events&version=1.0.0 // Install MSHelper.CQRS.Events as a Cake Tool #tool nuget:?package=MSHelper.CQRS.Events&version=1.0.0
MSHelper.CQRS.Events : Events
⭐ Star us on GitHub � it motivates us a lot!
Overview
Adds an ability to create and process Events in the sense of CQRS.
Installation
This document is for the latest MSHelper.CQRS.Events 1.0.0 release and later.
dotnet add package MSHelper.CQRS.Events
Dependencies
-- MSHelper
Usage
Implement IEvent
or IRejectedEvent
(marker) interface in the selected class. Since the event represents something that already happened, you should follow the convention:
--- keep all the events immutable --- name of your events should kept in the past tense
public class AccountCreated : IEvent
{
public Guid Id { get; }
public AccountCreated(id)
{
Id = id;
}
}
Create dedicated event handler class that implements IEventHandler<TEvent>
interface with HandleAsync()
method:
public class AccountCreatedHandler : IEventHandler<AccountCreated>
{
public Task HandleAsync(AccountCreated @event)
{
//put the handling code here
}
}
You can easily register all command handlers in DI container by calling AddEventHandlers()
method on IMSHelperBuilder:
public IServiceProvider ConfigureServices(this IServiceCollection services)
{
var builder = services.AddMSHelper()
.AddEventHandlers();
//other registrations
return builder.Build();
}
Dispatching a particular command object can be also done using MSHelper package. Start with registering in-memory dispatcher on your IMSHelperBuilder
by calling a AddInMemoryEventDispatcher()
method:
public IServiceProvider ConfigureServices(this IServiceCollection services)
{
var builder = services.AddMSHelper()
.AddCommandHandlers()
.AddInMemoryEventDispatcher();
//other registrations
return builder.Build();
}
Then simply inject IEventDispatcher
into a class and call DispatchAsync()
method:
public class AccountsService
{
private readonly IEventDispatcher _dispatcher;
public AccountsService(IEventDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
public Task PostProcessAccountCreation(AccountCreated @event)
=> _dispatcher.DispatchAsync(@event);
}
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.Events:
Package | Downloads |
---|---|
MSHelper.WebApi.CQRS
MSHelper.WebApi.CQRS - CQRS Integration. |
|
MSHelper.Logging.CQRS
MSHelper.Logging.CQRS - Centralized logging for CQRS with Serilog and Seq. |
|
MSHelper.MessageBrokers.CQRS
MSHelper.MessageBrokers.CQRS - Asynchronous messaging for CQRS using RabbitMQ. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 323 | 10/25/2022 |