ChainRunner 0.1.0
See the version list below for details.
dotnet add package ChainRunner --version 0.1.0
NuGet\Install-Package ChainRunner -Version 0.1.0
<PackageReference Include="ChainRunner" Version="0.1.0" />
paket add ChainRunner --version 0.1.0
#r "nuget: ChainRunner, 0.1.0"
// 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
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 | Versions 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. |
-
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.