MediFlow 1.2.0
dotnet add package MediFlow --version 1.2.0
NuGet\Install-Package MediFlow -Version 1.2.0
<PackageReference Include="MediFlow" Version="1.2.0" />
<PackageVersion Include="MediFlow" Version="1.2.0" />
<PackageReference Include="MediFlow" />
paket add MediFlow --version 1.2.0
#r "nuget: MediFlow, 1.2.0"
#:package MediFlow@1.2.0
#addin nuget:?package=MediFlow&version=1.2.0
#tool nuget:?package=MediFlow&version=1.2.0
MediFlow
MediFlow is a Mediator Based Communication System
Features
- Lightweight and efficient.
- Supports publish-subscribe, request-response, and one-way notifications.
- Simplifies working with decoupled services in distributed systems.
- Easy to integrate with existing applications.
- Supports commands and command handlers for request-response communication.
Installation
You can install the LightMediator NuGet package using the following command:
dotnet add package MediFlow
Usage
To reference only the contracts for SimpleMediator, which includes:
IRequest
(including generic variants)- Represents a command or query that expects a single response
INotification
- Represents an event broadcast to multiple handlers (if any)
Advanced Usage: Request + Notification
This example demonstrates how to combine a Request
(command/query) and a Notification
(event) in a real-world use case.
✅ This scenario uses only
Microsoft.Extensions.DependencyInjection.Abstractions
for DI registration — no framework-specific packages.
Install-Package Microsoft.Extensions.DependencyInjection.Abstractions
1. Define the Request and Notification
public class CreateCustomerCommand : IRequest<string>
{
public string Title { get; set; }
}
public class CustomerCreatedEvent : INotification
{
public Guid CustomerId { get; }
public CustomerCreatedEvent(Guid customerId)
{
CustomerId = customerId;
}
}
2. Implement the Handlers
public class CreateCustomerHandler : IRequestHandler<CreateCustomerCommand, string>
{
private readonly IMediFlow _mediator;
public CreateCustomerHandler(IMediFlow mediator)
{
_mediator = mediator;
}
public async Task<string> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
{
var id = Guid.NewGuid();
// Simulate persistence...
// Publish event
await _mediator.Publish(new CustomerCreatedEvent(id), cancellationToken);
return $"Customer '{request.Title}' created with ID {id}";
}
}
public class SendWelcomeEmailHandler : INotificationHandler<CustomerCreatedEvent>
{
public Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
{
Console.WriteLine($"Sending welcome email to customer {notification.CustomerId}");
return Task.CompletedTask;
}
}
3. Register the Handlers (Dependency Injection)
You can register everything manually if you want full control:
services.AddSingleton<IMediFlow, Mediflow>();
services.AddTransient<IRequestHandler<CreateCustomerCommand, string>, CreateCustomerHandler>();
services.AddTransient<INotificationHandler<CustomerCreatedEvent>, SendWelcomeEmailHandler>();
Or use assembly scanning with:
services.AddSimpleMediator();
4. Execute the Flow
public class CustomerAppService
{
private readonly IMediFlow _mediator;
public CustomerAppService(IMediFlow mediator)
{
_mediator = mediator;
}
public async Task<string> CreateCustomer(string title)
{
return await _mediator.Send(new CreateCustomerCommand { Title = title });
}
}
When the CreateCustomer
method is called:
CreateCustomerHandler
handles the request- It creates and persists the customer (simulated)
- It publishes a
CustomerCreatedEvent
SendWelcomeEmailHandler
handles the event
This structure cleanly separates commands (which change state and return a result) from notifications (which communicate to the rest of the system that something happened).
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection (>= 6.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.