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
<PackageReference Include="Muflone.Transport.InMemory" Version="10.2.2" />
<PackageVersion Include="Muflone.Transport.InMemory" Version="10.2.2" />
<PackageReference Include="Muflone.Transport.InMemory" />
paket add Muflone.Transport.InMemory --version 10.2.2
#r "nuget: Muflone.Transport.InMemory, 10.2.2"
#:package Muflone.Transport.InMemory@10.2.2
#addin nuget:?package=Muflone.Transport.InMemory&version=10.2.2
#tool nuget:?package=Muflone.Transport.InMemory&version=10.2.2
Muflone.Transport.InMemory
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+
Muflone10.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 | Versions 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. |
-
net10.0
- Muflone (>= 10.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Using an InMemory broker to dispath commands and events