assistant.net.messaging 0.5.182

dotnet add package assistant.net.messaging --version 0.5.182                
NuGet\Install-Package assistant.net.messaging -Version 0.5.182                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="assistant.net.messaging" Version="0.5.182" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add assistant.net.messaging --version 0.5.182                
#r "nuget: assistant.net.messaging, 0.5.182"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install assistant.net.messaging as a Cake Addin
#addin nuget:?package=assistant.net.messaging&version=0.5.182

// Install assistant.net.messaging as a Cake Tool
#tool nuget:?package=assistant.net.messaging&version=0.5.182                

assistant.net.messaging

Simple message exchange implementation designed to be extensible and flexible. It can handle variety tasks like sync/async communication between components, application layers, or distributed applications.

Default configuration

To add storage one of methods should be called:

var services = new ServiceCollection()
    .AddMessagingClient(b => ...) // adds dependencies and initial configuration
    .ConfigureMessagingClient(b => ...); // appends existing configuration (no dependencies are added)

where message handlers should be registered like an in-memory handler

services.ConfigureMessagingClient(b => b
    .AddHandler<LocalMessageHandler>() // by a type parameter
    .AddHandler(typeof(LocalMessageHandler)) // by a parameter
    .AddHandler(new LocalMessageHandler())); // or an instance

In order to have more flexible control over message handling or applying reusable aspects, interceptors can be configured

services.ConfigureMessagingClient(b => b
    .AddInterceptor<RequestMessageInterceptor>() // by a type parameter
    .AddInterceptor(typeof(RequestMessageInterceptor)) // by a parameter
    .AddInterceptor(new RequestMessageInterceptor())); // or an instance

Couple interceptors are already available out of box. Some of them have dependency to storage package which should be configured with appropriate provider. For example, default local implementation

services.ConfigureMessagingClient(b => b.UseLocal());
// or
services.ConfigureStorage(b => b.UseLocal());

Note It should be configured for each named messaging client. See named configuration for details.

Configuration extension

Messaging client configuration may be big and complicated so applying it again and again can be annoying and error-prone. But message configuration can help to avoid that

services.ConfigureMessagingClient(b => b
    .AddConfiguration<CustomMessageConfiguration>() // by a type parameter
    .AddConfiguration(new CustomMessageConfiguration())); // or an instance

public class CustomMessageConfiguration : IMessageConfiguration { ... }

Single message handler configuration

Some sophisticated scenarios may need to separate message type registration from actual handlers in opposite to default configuration and the single message handler can be used for the purpose.

So a message type can be registered in one place

services.ConfigureMessagingClient(b => b
    .AddSingle<SomeMessage>()
    .AddSingle(typeof(AnotherMessage)));

and a single message handler can be configured later in another place (or overridden if needed)

services.ConfigureMessagingClient(b => b.UseSpecificHandler()); // mongo or other

or configure it as a factory

services.ConfigureMessagingClient(b => b
    .UseSingleHandler((provider, messageType) => provider.GetRequiredService<CustomSingleHandler>()));

Back off message handler configuration

In case any message type should be handled or other way tracked, back off message handler can be used. It comes into play if no other handler was registered for a message.

Named configuration

Messaging client implementation is based on named options so you can have multiple named messaging client with different configurations.

var provider = new ServiceCollection()
    .AddMessagingClient()
    .ConfigureMessagingClient("name-1", o => o.UseLocal().AddHandler<LocalMessageHandler>())
    .ConfigureMessagingClient("name-2", o => o.UseMongo().AddSingle<SomeMessage>())
    .BuildServiceProvider();

using var scope1 = provider.CreateScopeWithNamedOptionContext("name-1");
using var scope2 = provider.CreateScopeWithNamedOptionContext("name-2");

var client1 = scope1.ServiceProvider.GetRequiredService<IMessagingClient>();
var client2 = scope2.ServiceProvider.GetRequiredService<IMessagingClient>();

Messaging client resolving

Once the client was properly configured it's instance can be resolved

var client = provider.GetRequiredService<IMessagingClient>();

 var response = await client.Request(new SomeMessage()); // sends the message and waits for response
 await client.Publish(new EventMessage()); // sends the message and returns immediately

Class definitions

// A message that expects response object
public class SomeMessage : IMessage<SomeResponse> { ... }
public class SomeResponse { ... }
// A response less message
public class EventMessage : IMessage { ... }
// A typed message handler
public class LocalMessageHandler : IMessageHandler<SomeMessage, SomeResponse> { ... }
// A handler that handles any message type
public class AnyMessageHandler : IAbstractHandler { ... }
// A message configuration
public class CustomMessageConfiguration : IMessageConfiguration { ... }
// A typed message interceptor for request operations
public class SomeMessageInterceptor : IMessageRequestInterceptor<SomeMessage, SomeResponse> { ... }
// A typed message interceptor for publish operations
public class EventMessageInterceptor : IMessagePublishInterceptor<EventMessage> { ... }
// A interceptor for request operations that intercept any message types
public class AnyMessageRequestInterceptor : IAbstractRequestInterceptor { ... }
// A interceptor for publish operations that intercept any message types
public class AnyPublishMessageInterceptor : IAbstractPublishInterceptor { ... }

Available providers

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on assistant.net.messaging:

Package Downloads
assistant.net.messaging.web.client

A client for remote WEB oriented message handling.

assistant.net.messaging.web.server

A server for remote WEB oriented message handling.

assistant.net.messaging.generic.client

Storage based message handling client.

assistant.net.messaging.generic.server

storage based message handling server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.182 716 5/8/2023
0.4.151 740 3/28/2023
0.4.145 749 3/22/2023
0.4.144 1,809 9/4/2022
0.4.140 1,815 8/13/2022
0.3.139 1,814 8/9/2022
0.3.138 1,800 8/7/2022
0.3.137 1,779 8/6/2022
0.3.135 1,858 7/14/2022
0.3.133 1,888 7/4/2022
0.3.127 1,840 6/26/2022
0.3.125 1,844 6/25/2022
0.3.123 1,917 6/23/2022
0.3.121 1,846 6/22/2022
0.3.119 1,805 6/20/2022
0.1.78 1,128 9/20/2021