Coordix 0.2.0

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

Coordix

A lightweight and straightforward mediator implementation for .NET applications with minimal setup.

Coordix NuGet Version
Coordix NuGet Downloads

Key Features

  • Built for maximum compatibility - Built with .NET Standard 2.1 for maximum compatibility across .NET platforms
  • Zero external dependencies - Completely standalone with no third-party dependencies (except Microsoft.Extensions.DependencyInjection)
  • High-performance design - Optimized for performance with cached delegates and minimal reflection overhead
  • DDD-friendly design - Support for plain domain events without library dependencies, keeping your domain model clean
  • Dependency Injection Native - Built from scratch to work seamlessly with Microsoft Dependency Injection
  • Comprehensive messaging types:
    • IRequest<TResponse> - For queries and commands that return a value
    • IRequest - For commands that don't return a value
    • INotification - For events and notifications
  • Automatic handler discovery - Automatically registers all handlers in your assemblies
  • Thread-safe - All operations are thread-safe and optimized for concurrent access

Performance Optimizations

Coordix is designed with performance in mind, implementing several optimization strategies:

Cached MethodInfo

  • MethodInfo caching: The Handle method's MethodInfo is cached per handler type using a ConcurrentDictionary
  • One-time reflection: GetMethod("Handle") is called only once per handler type, eliminating repeated reflection overhead
  • Thread-safe: All caches use ConcurrentDictionary for safe concurrent access

Compiled Delegates

  • Strongly-typed delegates: Instead of using MethodInfo.Invoke, Coordix uses compiled Expression Trees to create strongly-typed delegates
  • Direct invocation: Handlers are invoked through pre-compiled delegates, avoiding reflection overhead on every call
  • Type-specific caching: Separate delegate caches for:
    • Request handlers without return value
    • Request handlers with return value
    • Notification handlers

Performance Benefits

  • First invocation: Creates and caches the delegate (one-time overhead ~1-5ms)
  • Subsequent invocations: Direct delegate calls with near-native performance (<0.01ms)
  • Scalability: Performance improvements become more significant as handler invocation frequency increases

Getting Started

Installation

You can install the Coordix package via NuGet Package Manager or the .NET CLI:

dotnet add package Coordix

Quick Start

1. Register Coordix
using Coordix.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Register Coordix and automatically discover all handlers
builder.Services.AddCoordix();
2. Define a Request
using Coordix.Interfaces;

public class GetUserQuery : IRequest<UserDto>
{
    public int UserId { get; set; }
}

public class UserDto
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
}
3. Implement a Handler
using Coordix.Interfaces;

public class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto>
{
    private readonly IUserRepository _repository;

    public GetUserQueryHandler(IUserRepository repository)
    {
        _repository = repository;
    }

    public async Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
    {
        var user = await _repository.GetByIdAsync(request.UserId, cancellationToken);
        return new UserDto { Id = user.Id, Name = user.Name };
    }
}
4. Use the Mediator
public class UsersController : ControllerBase
{
    private readonly IMediator _mediator;

    public UsersController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpGet("{id}")]
    public async Task<ActionResult<UserDto>> GetUser(int id)
    {
        var user = await _mediator.Send(new GetUserQuery { UserId = id });
        return Ok(user);
    }
}

Examples

Simple Request/Response

// Request
public class GetUserQuery : IRequest<UserDto>
{
    public int UserId { get; set; }
}

// Handler
public class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto>
{
    public async Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
    {
        // Your logic here
        return new UserDto { Id = request.UserId, Name = "John" };
    }
}

// Usage
var user = await _mediator.Send(new GetUserQuery { UserId = 123 });

Command (No Response)

// Command
public class CreateUserCommand : IRequest
{
    public string Name { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
}

// Handler
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand>
{
    public async Task Handle(CreateUserCommand request, CancellationToken cancellationToken)
    {
        // Your logic here
        await SaveUserAsync(request);
    }
}

// Usage
await _mediator.Send(new CreateUserCommand { Name = "John", Email = "john@example.com" });

Notifications (Events)

// Notification
public class UserCreatedEvent : INotification
{
    public int UserId { get; }
    public string Email { get; }

    public UserCreatedEvent(int userId, string email)
    {
        UserId = userId;
        Email = email;
    }
}

// Handler
public class SendWelcomeEmailHandler : INotificationHandler<UserCreatedEvent>
{
    public async Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Send welcome email
        await SendEmailAsync(notification.Email, "Welcome!");
    }
}

// Usage
await _mediator.Publish(new UserCreatedEvent(userId, email));

Registration Options

// Scan all assemblies in the current AppDomain
services.AddCoordix();

// Scan specific assemblies
services.AddCoordix(typeof(MyHandler).Assembly);

// Scan by namespace prefix
services.AddCoordix("MyApp");

Manual Registration

services.AddSingleton<IMediator, Mediator>();
services.AddScoped<IRequestHandler<GetUserQuery, UserDto>, GetUserQueryHandler>();
services.AddTransient<INotificationHandler<UserCreatedEvent>, SendWelcomeEmailHandler>();

Compatibility Alias

If you're migrating from MediatR, you can use the AddMediator alias:

services.AddMediator(); // Same as AddCoordix()

Extension Packages

Coordix has extension packages that add additional functionality:

Coordix.Background

Coordix.Background NuGet Version

Background job processing for fire-and-forget in-process jobs:

dotnet add package Coordix.Background
// AddCoordixBackground automatically includes core services
services.AddCoordixBackground();

Note: You do not need to call AddCoordix() when using AddCoordixBackground(). The Background extension registers all core services automatically.

See the Background Jobs Guide for more information.

Documentation

For comprehensive documentation, visit the GitHub repository:

Core Documentation

Extension Packages

Examples

Check out the samples folder for complete, runnable examples:

  • Simple Sample - Basic usage with Send and Publish
  • Advanced Sample - Complete application with multiple handlers, events, and patterns

Requirements

  • .NET Standard 2.1 or higher
  • .NET Core 2.1+ / .NET 5+ / .NET 6+ / .NET 7+ / .NET 8+
  • Microsoft.Extensions.DependencyInjection (included with ASP.NET Core)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Coordix was developed by Gabriel Santana under the MIT license.

Give a Star! ⭐

If this project made your life easier, a star would mean a lot to us!


Made with ❤️ by the Coordix community

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Coordix:

Package Downloads
Coordix.CodeGen

Source generator extension for Coordix mediator. This package extends Coordix core with compile-time code generation capabilities for zero-reflection handler execution. Requires Coordix package to be installed.

Coordix.Background

Background job processing extension for Coordix mediator. This package extends Coordix core with fire-and-forget in-process background job capabilities. Requires Coordix package to be installed.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 516 11/25/2025
0.2.0-rc2 186 11/23/2025
0.2.0-rc 269 11/21/2025
0.0.3 232 4/21/2025
0.0.2 213 4/21/2025
0.0.1 208 4/21/2025