Cortex.Mediator 1.6.1

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

Cortex.Mediator 🧠

Cortex.Mediator is a lightweight and extensible implementation of the Mediator pattern for .NET applications, designed to power clean, modular architectures like Vertical Slice Architecture and CQRS.

Built as part of the Cortex Data Framework, this library simplifies command and query handling with built-in support for:

  • ✅ Commands & Queries
  • ✅ Notifications (Events)
  • ✅ Pipeline Behaviors
  • ✅ FluentValidation
  • ✅ Logging
  • ✅ Transaction Handling

GitHub License NuGet Version GitHub contributors Discord Shield

🚀 Getting Started

Install via NuGet

dotnet add package Cortex.Mediator

🛠️ Setup

In Program.cs or Startup.cs:

builder.Services.AddCortexMediator(
    builder.Configuration,
    new[] { typeof(Program) }, // Assemblies to scan for handlers
    options => options.AddDefaultBehaviors() // Logging, Validation, Transaction
);

📦 Folder Structure Example (Vertical Slice)

Features/
  CreateUser/
    CreateUserCommand.cs
    CreateUserCommandHandler.cs
    CreateUserValidator.cs
    CreateUserEndpoint.cs

✏️ Defining a Command

public class CreateUserCommand : ICommand
{
    public string UserName { get; set; }
    public string Email { get; set; }
}

Handler

public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand>
{
    public async Task Handle(CreateUserCommand command, CancellationToken cancellationToken)
    {
        // Logic here
    }
}

Validator (Optional, via FluentValidation)

public class CreateUserValidator : AbstractValidator<CreateUserCommand>
{
    public CreateUserValidator()
    {
        RuleFor(x => x.UserName).NotEmpty();
        RuleFor(x => x.Email).NotEmpty().EmailAddress();
    }
}

🔍 Defining a Query

public class GetUserQuery : IQuery<GetUserResponse>
{
    public int UserId { get; set; }
}
public class GetUserQueryHandler : IQueryHandler<GetUserQuery, GetUserResponse>
{
    public async Task<GetUserResponse> Handle(GetUserQuery query, CancellationToken cancellationToken)
    {
        return new GetUserResponse { UserId = query.UserId, UserName = "Andy" };
    }
}

📢 Notifications (Events)

public class UserCreatedNotification : INotification
{
    public string UserName { get; set; }
}

public class SendWelcomeEmailHandler : INotificationHandler<UserCreatedNotification>
{
    public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
    {
        // Send email...
    }
}
await mediator.PublishAsync(new UserCreatedNotification { UserName = "Andy" });

🔧 Pipeline Behaviors (Built-in)

Out of the box, Cortex.Mediator supports:

  • ValidationCommandBehavior
  • LoggingCommandBehavior
  • TransactionCommandBehavior

You can also register custom behaviors:

options.AddOpenCommandPipelineBehavior(typeof(MyCustomBehavior<>));

💬 Contributing

We welcome contributions from the community! Whether it's reporting bugs, suggesting features, or submitting pull requests, your involvement helps improve Cortex for everyone.

💬 How to Contribute

  1. Fork the Repository
  2. Create a Feature Branch
git checkout -b feature/YourFeature
  1. Commit Your Changes
git commit -m "Add your feature"
  1. Push to Your Fork
git push origin feature/YourFeature
  1. Open a Pull Request

Describe your changes and submit the pull request for review.

📄 License

This project is licensed under the MIT License.

📚 Sponsorship

Cortex is an open-source project maintained by BuilderSoft. Your support helps us continue developing and improving Cortex. Consider sponsoring us to contribute to the future of resilient streaming platforms.

How to Sponsor

  • Financial Contributions: Support us through GitHub Sponsors or other preferred platforms.
  • Corporate Sponsorship: If your organization is interested in sponsoring Cortex, please contact us directly.

Contact Us: cortex@buildersoft.io

Contact

We'd love to hear from you! Whether you have questions, feedback, or need support, feel free to reach out.

Thank you for using Cortex Data Framework! We hope it empowers you to build scalable and efficient data processing pipelines effortlessly.

Built with ❤️ by the Buildersoft team.

Product 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 is compatible.  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 is compatible.  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 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. 
.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. 
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.6.1 0 4/8/2025
1.6.0 44 4/5/2025
1.5.0 89 2/8/2025
1.4.0 109 1/18/2025
1.3.1 91 12/24/2024
1.3.0 81 12/24/2024
1.2.1 90 12/10/2024
1.2.0 98 12/9/2024
1.1.0 107 12/3/2024
1.0.0 170 6/27/2024

Just as the Cortex in our brains handles complex processing efficiently, Cortex Data Framework brings brainpower to your data management!