ApiGuidGeneratorBehaviour.cs 901 B

123456789101112131415161718192021222324252627282930
  1. using AipGateway.API.Application;
  2. namespace AipGateway.API.Middlewares
  3. {
  4. public class ApiGuidGeneratorBehaviour
  5. {
  6. private readonly ILogger<ApiGuidGeneratorBehaviour> _log;
  7. private readonly RequestDelegate _next;
  8. public ApiGuidGeneratorBehaviour(ILogger<ApiGuidGeneratorBehaviour> log, RequestDelegate next)
  9. {
  10. _log = log;
  11. _next = next;
  12. }
  13. public async Task InvokeAsync(HttpContext context)
  14. {
  15. string requestUrl = context.Request.Path;
  16. if (requestUrl.Contains(GlobalConstants.API_PREFIX))
  17. {
  18. string guid = Guid.NewGuid().ToString();
  19. context.Items[GlobalConstants.API_GUID] = guid;
  20. context.Items[GlobalConstants.API_START_TM] = DateTime.Now;
  21. }
  22. await _next(context);
  23. return;
  24. }
  25. }
  26. }