MSHelper.MessageBrokers.CQRS
1.0.0
dotnet add package MSHelper.MessageBrokers.CQRS --version 1.0.0
NuGet\Install-Package MSHelper.MessageBrokers.CQRS -Version 1.0.0
<PackageReference Include="MSHelper.MessageBrokers.CQRS" Version="1.0.0" />
paket add MSHelper.MessageBrokers.CQRS --version 1.0.0
#r "nuget: MSHelper.MessageBrokers.CQRS, 1.0.0"
// Install MSHelper.MessageBrokers.CQRS as a Cake Addin #addin nuget:?package=MSHelper.MessageBrokers.CQRS&version=1.0.0 // Install MSHelper.MessageBrokers.CQRS as a Cake Tool #tool nuget:?package=MSHelper.MessageBrokers.CQRS&version=1.0.0
MSHelper.MessageBrokers.CQRS : CQRS Integration for Asynchronous messaging using RabbitMQ.
⭐ Star us on GitHub � it motivates us a lot!
Overview
MSHelper allows you to integrate asynchronous communication with CQRS principle providing set of extension methods for publishing/subscribing commands and events.
Installation
This document is for the latest MSHelper.MessageBrokers.CQRS 1.0.0 release and later.
dotnet add package MSHelper.MessageBrokers.CQRS
Dependencies
-- MSHelper
Usage
To subscribe for a particular command or event, invoke UseRabbitMq()
method on IApplicationBuilder
and call SubscribeCommand<TCommand>()
or SubscribeEvent<TCommand>()
.
public void Configure(this IApplicationBuilder app)
{
app.UseRabbitMq()
.SubscribeCommand<CreateUser>()
.SubscribeEvent<UserCreated>();
}
Once the message is received, it gets distpatched using ICommandDispatcher
or IEventDispatcher
.
To publish a message simply inject IBusPublsiher
into any class you want and invoke SendAsync()
(for commands) or PublishAsync()
(for event) passing the message and correlation context.
public class CustomBusPublisher
{
private readonly IBusPublisher _publisher;
public CustomBusPublisher(IBusPublisher publisher)
{
_publisher = publisher;
}
public Task PublishCommandAsync<TCommand>(TCommand command) where T : class, ICommand
=> _publisher.SendAsync(command);
public Task PublishEventAsync<TEvent>(TEvent @event) where T : class, IEvent
=> _publisher.PublishAsync(@event);
}
This package also allows you register async dispatcher instead of �in-memory�. Extend IMSHelperBuilder
with AddServiceBusCommandDispatcher()
or AddServiceBusEventDispatchermethod()
:
public IServiceProvider ConfigureServices(this IServiceCollection services)
{
var builder = services.AddMSHelper()
.AddQueryHandlers()
.AddServiceBusCommandDispatcher()
.AddServiceBusEventDispatcher();
//other registrations
return builder.Build();
}
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.CQRS.Commands (>= 1.0.0)
- MSHelper.CQRS.Events (>= 1.0.0)
- MSHelper.MessageBrokers (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 213 | 10/25/2022 |