Skip to content

A utility library allowing for easy CancellationToken usage

License

Notifications You must be signed in to change notification settings

soenneker/soenneker.utils.cancellation

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Languages