You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.Extensions.Options;
  5. using WebApiWebSem.Dbo;
  6. namespace WebApiWebSem.Middleware
  7. {
  8. public class SleepMiddleware
  9. {
  10. private readonly RequestDelegate _next;
  11. private readonly AppConfigDbo _options;
  12. public SleepMiddleware(RequestDelegate next, IOptions<AppConfigDbo> options)
  13. {
  14. _next = next;
  15. _options = options.Value;
  16. }
  17. public async Task Invoke(HttpContext context)
  18. {
  19. if (_options.SleepTime > 0)
  20. {
  21. Thread.Sleep(_options.SleepTime);
  22. }
  23. await _next.Invoke(context);
  24. }
  25. }
  26. }