soenneker / soenneker.utils.cancellation

A utility library allowing for easy CancellationToken usage

Home Page:https://soenneker.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Soenneker.Utils.Cancellation

A utility library allowing for easy CancellationToken usage

Installation

dotnet add package Soenneker.Utils.Cancellation

Usage

  1. Register the interop within DI (Program.cs).
public static async Task Main(string[] args)
{
    ...
    builder.Services.AddCancellationUtil();
}
  1. Inject ICancellationUtil where you wish to set the CancellationToken (typically from an API Controller)
_cancellationUtil.Set(cancellationToken);
  1. Inject ICancellationUtil where you wish to retrieve the CancellationToken (typically when accessing another API, or database etc):
// is not guaranteed to be non-null (if it never was set within scope), but is specified thus for ease of use
var cancellationUtil = _cancellationUtil.Get(); 

About

A utility library allowing for easy CancellationToken usage

https://soenneker.com

License:MIT License


Languages

Language:C# 100.0%