VitalRouter.Extensions.DependencyInjection 2.0.5

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

VitalRouter

GitHub license Unity 2022.2+

VitalRouter is a C# library for zero-allocation, in-memory messaging on the client-side.

It works on any platform where C# runs, but is specifically designed for client-side applications, particularly in games with Unity, or where event propagation can become complex.

By simply adding an Attribute, you can achieve asynchronous handlers, asynchronous middleware, sequence control, and more. Roslyn SourceGenerator generates high-performance code with zero allocations. It can function as a thin framework that promotes a unidirectional control flow.

[Routes]
[Filter(typeof(Logging))]
[Filter(typeof(ExceptionHandling))]
[Filter(typeof(GameStateUpdating))]
public partial class ExamplePresenter
{
    // Declare event handler
    [Route]
    void On(FooCommand cmd)
    {
        // Do something ...
        Console.WriteLine("foo !")
    }

    // Declare event handler (async)
    [Route] 
    async UniTask On(BarCommand cmd)
    {
        // Do something for await ...
    }
    
    // Declare event handler with extra filter
    [Route]
    [Filter(typeof(ExtraFilter))]
    async UniTask On(BuzCommand cmd, CancellationToken cancellation = default)
    {
        // Do something after all filters runs on.
    }
       
    // Declare event handler with specifies behavior when async handlers are executed concurrently
    [Route(CommandOrdering.Sequential)]
    async UniTask On(BuzCommand cmd, CancellationToken cancellation = default)
    {
        // Do something after all filters runs on.
    }
}
// Subscribe with async
var subscription = router.SubscribeAwait<FooCommand>(async (cmd, cancellationToken) => { /* ... */ }, CommandOrdering.Sequential);

// lambda interceptors
router
    .WithFilter<FooCommand>(async (x, context) =>
    {
        if (condition) await next(x, context);
    })
    .Subscribe<FooCommand>(cmd => { /* .. */ });
var router = new Router();

var presenter = new ExamplePresenter();
presenter.MapTo(router);

await router.PublishAsync(new FooCommand(/* ... */));
// foo !

In games, or complex GUI application development, patterns such as central event aggregator/message broker/mediator are powerful patterns to organize N:N relationships. Assembling an asynchronous function pipeline can be even more effective.

Features

  • Zero allocation message passing
  • Thread-safe
  • Pub/Sub, Fan-out
  • Async / Non-async handlers
  • Fast declarative routing pattern
  • Naive event handler pattern
  • Async interceptor pipelines
    • Parallel, queueing, or other sequential control.
  • DI friendly. Also support without DI.
  • Optional Extensions
    • UniTask support
    • R3 integration
    • MRuby scripting

Documentation

Visit vitalrouter.hadashikick.jp to see the full documentation.

Installation

Starting with version 2.0, distribution in Unity has been changed to NuGet. For documentation prior to version 1.x, please refer to v1 branch.

The following NuGet packages are available.

Package Latest version
VitalRouter NuGet
VitalRouter.Extensions.DependencyInjection NuGet
VitalRouter.R3 NuGet
VitalRouter.MRuby NuGet

Unity

Requirements: Unity 20222.2+ This limitation is due to the use of the Incremental Source Generator.

  1. Install NugetForUnity.
  2. Open the NuGet window by going to NuGet > Manage NuGet Packages, after search for the "VitalRouter" packages, and install it.
  3. Optional
    • The following extensions for Unity are available from the Unity Package Manager:
      • https://github.com/hadashiA/VitalRouter.git?path=/src/VitalRouter.Unity/Assets/VitalRouter#2.0.5
        
      • Install UniTask >= 2.5.5
        • If UniTask is installed, VITALROUTER_UNITASK_INTEGRATION flag is turned on and the optimized GC-free code is executed.
        • See UniTask Integration section for more details.
      • Install VContainer >= 1.16.6
        • For bringing in DI style, VitalRouter supports Integration with VContainer, a fast and lightweight DI container for Unity.
        • See DI section for more details.

Async interceptor pipeline

Pipelining of async interceptors for published messages is possible. This is a general strong pattern for data exchange.

<img src="./website/docs/assets/diagram_interceptors.svg" alt="Interceptor Diagram" width="50%" />

Read more

UniTask Integration

UniTask is a fast async/await extension for Unity. VitalRouter actively supports UniTask.

Read more

R3 Integration

R3 is the next generation Reactive Extensions implementation in the C# world. It is an excellent alternative to asynchronous streams, but also an excellent alternative to local events.

VitalRouter supports the ability to work with R3.

Read more

MRuby scripting

It is very powerful if the publishing of commands can be controlled by external data.

For example, when implementing a game scenario, most of the time we do not implement everything in C# scripts. It is common to express large amounts of text data, branching, flag management, etc. in a simple scripting language or data format.

VitalRouter offers an optional package for this purpose before integrating mruby. (blog / blog (Japanease)

Fiber in mruby and async/await in C# are fully integrated.

MRuby and C# Diagram

Read more

LISENCE

MIT

AUTHOR

@hadashiA

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 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 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
2.0.5 96 12/31/2025
2.0.4 260 12/15/2025
2.0.3 164 11/7/2025
2.0.2 202 11/3/2025
2.0.1 187 10/31/2025
2.0.0 184 10/5/2025
1.7.0 192 7/15/2025
1.6.5 285 5/12/2025
1.6.2 163 12/31/2024
1.6.1 196 11/23/2024
1.6.0 153 11/15/2024
1.5.0 161 10/28/2024
1.4.7 144 10/21/2024
1.4.6 196 10/18/2024
1.4.5 159 10/13/2024
1.4.4 202 10/11/2024
1.4.3 156 10/4/2024
1.4.2 166 10/1/2024
1.4.1 151 9/24/2024
1.4.0 166 9/22/2024
1.3.0 161 9/21/2024
1.2.2 211 9/14/2024
1.2.1 180 9/13/2024
1.2.0 185 9/8/2024
1.1.0 169 9/7/2024
1.0.1 168 9/7/2024
1.0.0 2,371 8/4/2024
0.9.4 159 8/4/2024
0.9.3 189 6/15/2024
0.9.2 205 5/27/2024
0.9.1 222 4/9/2024
0.9.0 191 3/19/2024
0.8.1 229 3/3/2024
0.8.0 198 2/28/2024
0.7.1 201 2/20/2024