Muflone.Transport.InMemory 10.2.2

dotnet add package Muflone.Transport.InMemory --version 10.2.2
                    
NuGet\Install-Package Muflone.Transport.InMemory -Version 10.2.2
                    
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="Muflone.Transport.InMemory" Version="10.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muflone.Transport.InMemory" Version="10.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Muflone.Transport.InMemory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muflone.Transport.InMemory --version 10.2.2
                    
#r "nuget: Muflone.Transport.InMemory, 10.2.2"
                    
#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.
#:package Muflone.Transport.InMemory@10.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muflone.Transport.InMemory&version=10.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Muflone.Transport.InMemory&version=10.2.2
                    
Install as a Cake Tool

Muflone.Transport.InMemory

NuGet License: MIT

InMemory transport for Muflone, providing an in-process service bus to dispatch commands and publish events without any external broker dependency. Ideal for development, testing, and lightweight production scenarios.


Requirements

  • .NET 10.0+
  • Muflone 10.0.1+

Installation

Package Manager

Install-Package Muflone.Transport.InMemory

.NET CLI

dotnet add package Muflone.Transport.InMemory

Getting Started

1. Register the transport

Call AddMufloneTransportInMemory on your IServiceCollection during application startup:

builder.Services.AddMufloneTransportInMemory();

This registers the following services:

Service Implementation Lifetime
IMessageSubscriber InMemorySubscriber Singleton
IServiceBus InMemoryBus Singleton
IEventBus InMemoryBus Singleton
MessageHandlersStarter Hosted service —

2. Send a command

Inject IServiceBus and call SendAsync:

public class MyService(IServiceBus serviceBus)
{
    public async Task DoSomethingAsync(CancellationToken cancellationToken)
    {
        var command = new MyCommand(Guid.NewGuid());
        await serviceBus.SendAsync(command, cancellationToken);
    }
}

3. Publish an event

Inject IEventBus and call PublishAsync:

public class MyService(IEventBus eventBus)
{
    public async Task NotifyAsync(CancellationToken cancellationToken)
    {
        var @event = new MyEvent(Guid.NewGuid());
        await eventBus.PublishAsync(@event, cancellationToken);
    }
}

How It Works

InMemoryBus

InMemoryBus implements both IServiceBus (commands) and IEventBus (events). When a message is dispatched, it looks up registered subscribers via InMemorySubscriber and writes the message directly into each subscriber's .NET Channel<object>.

InMemorySubscriber

InMemorySubscriber maintains a ConcurrentDictionary mapping message types to their IInMemoryChannel instances. Each subscriber gets an unbounded System.Threading.Channels.Channel that is read asynchronously and forwarded to the corresponding handler. Namespace-agnostic lookup is also supported, so commands/events with the same type name but different namespaces are matched correctly.

MufloneBroker (static)

MufloneBroker provides a lightweight static alternative that stores dispatched messages in ObservableCollection properties — useful in tests or simple scenarios:

MufloneBroker.Send(command);    // adds to MufloneBroker.Commands
MufloneBroker.Publish(@event);  // adds to MufloneBroker.Events

Sample Project

See a working example at BrewUp.


Authors

  • Alberto Acerbis
  • Alessandro Colla

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
10.2.2 111 11/7/2026
10.0.1 404 12/18/2025
8.0.3 500 12/10/2025
8.0.2 281 10/16/2024
8.0.1 248 10/16/2024
8.0.0 251 10/16/2024
6.0.3 415 4/23/2023
6.0.2 335 4/10/2023
6.0.1 365 4/6/2023
6.0.0 392 1/9/2023

Using an InMemory broker to dispath commands and events