Routya.Core 1.0.0-alpha.4

This is a prerelease version of Routya.Core.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Routya.Core --version 1.0.0-alpha.4
                    
NuGet\Install-Package Routya.Core -Version 1.0.0-alpha.4
                    
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="Routya.Core" Version="1.0.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Routya.Core" Version="1.0.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="Routya.Core" />
                    
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 Routya.Core --version 1.0.0-alpha.4
                    
#r "nuget: Routya.Core, 1.0.0-alpha.4"
                    
#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 Routya.Core@1.0.0-alpha.4
                    
#: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=Routya.Core&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Routya.Core&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Tool

Routya

CI NuGet Downloads

Routya is a fast, lightweight message dispatching library built for .NET applications that use the CQRS pattern.
It provides a flexible way to route requests/responses and notifications to their respective handlers with minimal overhead and high performance.

๐Ÿšง Routya is currently in alpha โ€” APIs may change as we refine the design and gather feedback.


โœจ Features

  • โœ… Clean interface-based abstraction for Requests/Responses and Notifications
  • ๐Ÿš€ High-performance dispatching via compiled delegates (no reflection or dynamic resolution)
  • ๐Ÿงฉ Optional pipeline behavior support for cross-cutting concerns
  • ๐Ÿ”„ Supports both sequential and parallel notification dispatching
  • โ™ป๏ธ Simple to extend and integrate with your existing architecture
  • ๐Ÿงช Built with performance and clarity in mind

๐Ÿ“ฆ NuGet Package

Latest prerelease version:

dotnet add package Routya.Core --version 1.0.0-alpha.4

๐Ÿš€ Quick Start

Dependency injection

On startup you can define if Routya should create a new instance of the service provider each time it is called or work on the root service provider.

Note!!! By default scope is enabled

Scoped

    builder.Services.AddRoutya(cfg => cfg.Scope = RoutyaDispatchScope.Scoped, Assembly.GetExecutingAssembly());

Root

    builder.Services.AddRoutya(cfg => cfg.Scope = RoutyaDispatchScope.Root, Assembly.GetExecutingAssembly());

You can add an auto registration of IRequestHandler, IAsyncRequestHandler and INotificationHandler by adding the executing assembly

Note!!! By default you would have to manually register your Requests/Notifications and Handlers

    builder.Services.AddRoutya(cfg => cfg.Scope = RoutyaDispatchScope.Scoped, Assembly.GetExecutingAssembly());

Requests

๐Ÿ“Š Benchmark Results

Note! Benchmarks were run with handlers returning only a string using BenchmarkDotNet | Method | Mean | Error | StdDev | Code Size | Allocated | |----------------- |----------:|---------:|---------:|----------:|----------:| | Routya_Send | 76.59 us | 1.491 us | 1.831 us | 8,684 B | 6.31 KB | | Routya_SendAsync | 246.53 us | 1.848 us | 1.638 us | 8,813 B | 8.94 KB |

Define a request

    public class HelloRequest(string name) : IRequest<string>
    {
        public string Name { get; } = name;
    }

Implement the Sync handler ...

    public class HelloSyncHandler : IRequestHandler<HelloRequest, string>
    {
        public string Handle(HelloRequest request)
        {
            return $"Hello, {request.Name}!";
        }
    }

or Implement the async handler

    public class HelloAsyncHandler : IAsyncRequestHandler<HelloRequest, string>
    {
        public async Task<string> HandleAsync(HelloRequest request, CancellationToken cancellationToken)
        {
            return await Task.FromResult($"[Async] Hello, {request.Name}!");
        }
    }

Inject the IRoutya interface and dispatch your requests in sync...

public class Example : ControllerBase
{
  private readonly IRoutya _dispatcher;

  public Example(IRoutya dispatcher)
  {
     _dispatcher = dispatcher
  }
}
    _dispatcher.Send<HelloRequest, string>(new HelloRequest("Sync World"));

or async

    await _dispatcher.SendAsync<HelloRequest, string>(new HelloRequest("Async World"));

Notifications

๐Ÿ“Š Benchmark Results

Note! Benchmarks were run with handlers returning only Task.Completed using BenchmarkDotNet | Method | Mean | Error | StdDev | Code Size | Gen0 | Allocated | |-------------------------- |---------:|--------:|--------:|----------:|-------:|----------:| | RoutyaCompiled_Sequential | 315.9 ns | 2.21 ns | 1.96 ns | 368 B | 0.0019 | 528 B | | RoutyaCompiled_Parallel | 338.1 ns | 2.84 ns | 2.52 ns | 368 B | 0.0024 | 648 B |

Define your notification

  public class UserRegisteredNotification(string email) : INotification
  {
      public string Email { get; } = email;
  }

Define your handlers

  public class LogAnalyticsHandler : INotificationHandler<UserRegisteredNotification>
  {
      public async Task Handle(UserRegisteredNotification notification, CancellationToken cancellationToken = default)
      {
          await Task.Delay(100, cancellationToken);
          Console.WriteLine($"๐Ÿ“Š Analytics event logged for {notification.Email}");
      }
  }
  public class SendWelcomeEmailHandler : INotificationHandler<UserRegisteredNotification>
  {
      public async Task Handle(UserRegisteredNotification notification, CancellationToken cancellationToken = default)
      {
          await Task.Delay(200, cancellationToken);
          Console.WriteLine($"๐Ÿ“ง Welcome email sent to {notification.Email}");
      }
  }

Inject the IRoutya interface and dispatch your notifications sequentially...

public class Example : ControllerBase
{
  private readonly IRoutya _dispatcher;

  public Example(IRoutya dispatcher)
  {
     _dispatcher = dispatcher
  }
}
    await dispatcher.PublishAsync(new UserRegisteredNotification("john.doe@example.com"));

or in parallel

     await dispatcher.PublishParallelAsync(new UserRegisteredNotification("john.doe@example.com"));
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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.