From 4de0912f85183b74008d8d7621c555df71af5722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 15 Dec 2017 14:51:10 +0300 Subject: [PATCH] Implemented HttpContextCancellationTokenProvider. --- .../Volo.Abp.AspNetCore.csproj.DotSettings | 2 ++ .../HttpContextCancellationTokenProvider.cs | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj.DotSettings create mode 100644 src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Threading/HttpContextCancellationTokenProvider.cs diff --git a/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj.DotSettings b/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Threading/HttpContextCancellationTokenProvider.cs b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Threading/HttpContextCancellationTokenProvider.cs new file mode 100644 index 0000000000..4757ce2f93 --- /dev/null +++ b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Threading/HttpContextCancellationTokenProvider.cs @@ -0,0 +1,20 @@ +using System.Threading; +using Microsoft.AspNetCore.Http; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Threading; + +namespace Volo.Abp.AspNetCore.Threading +{ + [Dependency(ReplaceServices = true)] + public class HttpContextCancellationTokenProvider : ICancellationTokenProvider, ITransientDependency + { + public CancellationToken Token => _httpContextAccessor.HttpContext?.RequestAborted ?? default; + + private readonly IHttpContextAccessor _httpContextAccessor; + + public HttpContextCancellationTokenProvider(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + } +}