-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainContextMiddleware.cs
40 lines (32 loc) · 1.06 KB
/
DomainContextMiddleware.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using WebApp.Models;
using WebApp.Security;
namespace WebApp.Middleware
{
public class DomainContextMiddleware
{
private readonly RequestDelegate _next;
public DomainContextMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext, IDomainContextAccessor contextAccessor)
{
var context = new DomainContext();
context.JobInfo = new Job { JobId = Guid.NewGuid().ToString(), ThreadId = Thread.CurrentThread.ManagedThreadId, Start = DateTime.Now };
DomainContext.Current = context;
await _next(httpContext);
}
}
public static class DomainContextMiddlewareExtensions
{
public static IApplicationBuilder UseDomainContext(this IApplicationBuilder builder)
{
return builder.UseMiddleware<DomainContextMiddleware>();
}
}
}