BasicMediatorCore 1.0.0

dotnet add package BasicMediatorCore --version 1.0.0
                    
NuGet\Install-Package BasicMediatorCore -Version 1.0.0
                    
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="BasicMediatorCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BasicMediatorCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BasicMediatorCore" />
                    
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 BasicMediatorCore --version 1.0.0
                    
#r "nuget: BasicMediatorCore, 1.0.0"
                    
#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 BasicMediatorCore@1.0.0
                    
#: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=BasicMediatorCore&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BasicMediatorCore&version=1.0.0
                    
Install as a Cake Tool

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 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. 
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
1.0.0 133 8/13/2025