BasicMediatorCore 1.0.0
dotnet add package BasicMediatorCore --version 1.0.0
NuGet\Install-Package BasicMediatorCore -Version 1.0.0
<PackageReference Include="BasicMediatorCore" Version="1.0.0" />
<PackageVersion Include="BasicMediatorCore" Version="1.0.0" />
<PackageReference Include="BasicMediatorCore" />
paket add BasicMediatorCore --version 1.0.0
#r "nuget: BasicMediatorCore, 1.0.0"
#:package BasicMediatorCore@1.0.0
#addin nuget:?package=BasicMediatorCore&version=1.0.0
#tool nuget:?package=BasicMediatorCore&version=1.0.0
BasicMediatorCore
BasicMediatorCore is a lightweight C# implementation of the Mediator pattern designed to reduce coupling between components in your application by centralizing communication through a mediator.
📦 Installation
Install via NuGet Package Manager: Install-Package BasicMediatorCore Or via .NET CLI: dotnet add package BasicMediatorCore
🚀 Quick Start
Register the Mediator in your Startup/Program.cs:
// Scan all handlers in the current assembly
services.AddMediator(AppDomain.CurrentDomain.Load("YourAssemblyName"));
OR specify interfaces and implementations separately
services.AddMediator(
AppDomain.CurrentDomain.Load("YourAssemblyName.Interfaces"),
AppDomain.CurrentDomain.Load("YourAssemblyName.Implementations")
);
Create a command/event
public sealed class SampleCommand : IPublish
{
public string Message { get; set; }
}
Create a handler:
internal sealed class SampleCommandHandler : IPublishHandler<SampleCommand>
{
public async Task Handle(SampleCommand command, CancellationToken cancellationToken)
{
Console.WriteLine($"Received: {command.Message}");
// Your business logic here
}
}
Use in your controller/service:
public sealed class SampleController(IMediator mediator) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> SendMessage()
{
try
{
await _mediator.Publish(new SampleCommand { Message = "Hello World" });
return Ok();
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
}
✨ Features
- Simple Mediator pattern implementation
- Reduces direct dependencies between components
- Async support
- Easy integration with ASP.NET Core
- Lightweight and performant
📚 Usage Patterns
Basic Command:
public sealed class CreateUserCommand(string userName, string email) : IPublish
{
public string Username { get; internal set; } = userName;
public string Email { get; internal set; } = email;
}
internal sealed class CreateUserHandler : IPublishHandler<CreateUserCommand>
{
public async Task Handle(CreateUserCommand command, CancellationToken cancellationToken)
{
// User creation logic
}
}
Using in Services:
public sealed class UserService(IMediator mediator)
{
public async Task CreateUser(string username, string email)
{
await mediator.Publish(new CreateUserCommand
{
Username = username,
Email = email
});
}
}
🤝 Contributing Contributions are welcome! Please open an issue or submit a pull request.
📄 License MIT License - see LICENSE for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.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 | 133 | 8/13/2025 |