123456789101112131415161718192021222324252627282930 |
- using AipGateway.API.Application;
- namespace AipGateway.API.Middlewares
- {
- public class ApiGuidGeneratorBehaviour
- {
- private readonly ILogger<ApiGuidGeneratorBehaviour> _log;
- private readonly RequestDelegate _next;
- public ApiGuidGeneratorBehaviour(ILogger<ApiGuidGeneratorBehaviour> log, RequestDelegate next)
- {
- _log = log;
- _next = next;
- }
- public async Task InvokeAsync(HttpContext context)
- {
- string requestUrl = context.Request.Path;
- if (requestUrl.Contains(GlobalConstants.API_PREFIX))
- {
- string guid = Guid.NewGuid().ToString();
- context.Items[GlobalConstants.API_GUID] = guid;
- context.Items[GlobalConstants.API_START_TM] = DateTime.Now;
- }
- await _next(context);
- return;
- }
- }
- }
|