-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99ddb0e
commit ad30dbb
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace NetCorePal.Extensions.AspNetCore; | ||
|
||
public interface IRequestCancellationToken | ||
{ | ||
CancellationToken? CancellationToken { get; } | ||
} | ||
|
||
public class HttpContextAccessorRequestAbortedHandler : IRequestCancellationToken | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public HttpContextAccessorRequestAbortedHandler(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
} | ||
|
||
public CancellationToken? CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NetCorePal.Extensions.AspNetCore; | ||
|
||
namespace NetCorePal.Extensions.DependencyInjection; | ||
|
||
public static class ServiceCollectionExtension | ||
{ | ||
public static IServiceCollection AddRequestCancellationToken(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<IRequestCancellationToken, HttpContextAccessorRequestAbortedHandler>(); | ||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters