ChainRunner 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ChainRunner --version 0.1.0                
NuGet\Install-Package ChainRunner -Version 0.1.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="ChainRunner" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChainRunner --version 0.1.0                
#r "nuget: ChainRunner, 0.1.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.
// Install ChainRunner as a Cake Addin
#addin nuget:?package=ChainRunner&version=0.1.0

// Install ChainRunner as a Cake Tool
#tool nuget:?package=ChainRunner&version=0.1.0                

ChainRunner

.NET 5 CI NuGet

A simple and innovative library to implement chain of responsibilities. To learn more about chain of responsibilities pattern, read the following article https://refactoring.guru/design-patterns/chain-of-responsibility

  • Written in .NET 5
  • No Dependencies
  • No Reflection
  • Easy to Read and Use

Installation

Depending on your usage, follow one of the guidelines below.

ASP.NET Core

Install with NuGet:

Install-Package ChainRunner
Install-Package ChainRunner.Extensions.MicrosoftDependencyInjection

or with .NET CLI:

dotnet add package ChainRunner
dotnet add package ChainRunner.Extensions.MicrosoftDependencyInjection

and configure your desired as below in the ConfigureServices method of Startup.cs:

    services.AddChain<ChainRequest>()
            .WithHandler<ResponsibilityHandler1>()
            .WithHandler<ResponsibilityHandler2>()
            .WithHandler<ResponsibilityHandler3>();

Usages

Using the class below you intend to send notifications to your desired user in the form of email, SMS and Telegram message.

    public class SendNotificationRequest
    {
        public string UserId { get; set; }
    }

For each form of notification, you create a responsibility handler.

    public class SendEmailHandler : IResponsibilityHandler<SendNotificationRequest>
    {
        public Task HandleAsync(SendNotificationRequest request, CancellationToken cancellationToken = default)
        {
            // send notification using email
        }
    }
    
    public class SendSmsHandler : IResponsibilityHandler<SendNotificationRequest>
    {
        public Task HandleAsync(SendNotificationRequest request, CancellationToken cancellationToken = default)
        {
            // send notification using sms
        }
    }
    
    public class SendTelegramMessageHandler : IResponsibilityHandler<SendNotificationRequest>
    {
        public Task HandleAsync(SendNotificationRequest request, CancellationToken cancellationToken = default)
        {
            // send notification using Telegram message
        }
    }

Setup your chain in DI container

    services.AddChain<SendNotificationRequest>()
            .WithHandler<SendEmailHandler>()
            .WithHandler<SendSmsHandler>()
            .WithHandler<SendTelegramMessageHandler>();

Inject your chain to your class and run it

    [ApiController]
    [Route("[controller]")]
    public class NotificationController
    {
        private readonly IChain<ChainRequest> _chain;

        public NotificationController(IChain<ChainRequest> chain)
        {
            _chain = chain;
        }

        [HttpPost]
        public async Task<IActionResult> SendNotification(SendNotificationRequest request)
        {
            await _chain.RunAsync(request);

            return Ok();
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ChainRunner:

Package Downloads
ChainRunner.Extensions.MicrosoftDependencyInjection

simple and innovative library to implement a chain of responsibilities

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.0 63,908 1/5/2023
0.5.0 8,858 7/26/2022
0.4.1 18,625 7/12/2021
0.4.0 412 7/11/2021
0.3.0 455 7/10/2021
0.2.0 883 6/14/2021
0.1.1 439 6/1/2021
0.1.0 430 6/1/2021