Cortex.Mediator
1.6.1
dotnet add package Cortex.Mediator --version 1.6.1
NuGet\Install-Package Cortex.Mediator -Version 1.6.1
<PackageReference Include="Cortex.Mediator" Version="1.6.1" />
<PackageVersion Include="Cortex.Mediator" Version="1.6.1" />
<PackageReference Include="Cortex.Mediator" />
paket add Cortex.Mediator --version 1.6.1
#r "nuget: Cortex.Mediator, 1.6.1"
#addin nuget:?package=Cortex.Mediator&version=1.6.1
#tool nuget:?package=Cortex.Mediator&version=1.6.1
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
🚀 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
- Fork the Repository
- Create a Feature Branch
git checkout -b feature/YourFeature
- Commit Your Changes
git commit -m "Add your feature"
- Push to Your Fork
git push origin feature/YourFeature
- 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.
- Email: cortex@buildersoft.io
- Website: https://buildersoft.io
- GitHub Issues: Cortex Data Framework Issues
- Join our Discord Community:
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 | 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 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. |
-
.NETStandard 2.1
- FluentValidation (>= 11.11.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.11.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Scrutor (>= 6.0.1)
-
net7.0
- FluentValidation (>= 11.11.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.11.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Scrutor (>= 6.0.1)
-
net8.0
- FluentValidation (>= 11.11.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.11.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Scrutor (>= 6.0.1)
-
net9.0
- FluentValidation (>= 11.11.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.11.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Scrutor (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Just as the Cortex in our brains handles complex processing efficiently, Cortex Data Framework brings brainpower to your data management!