1234567891011121314151617181920212223242526272829 |
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Options;
- using WebApiWebSem.Dbo;
-
- namespace WebApiWebSem.Middleware
- {
- public class SleepMiddleware
- {
- private readonly RequestDelegate _next;
- private readonly AppConfigDbo _options;
-
- public SleepMiddleware(RequestDelegate next, IOptions<AppConfigDbo> options)
- {
- _next = next;
- _options = options.Value;
- }
-
- public async Task Invoke(HttpContext context)
- {
- if (_options.SleepTime > 0)
- {
- Thread.Sleep(_options.SleepTime);
- }
- await _next.Invoke(context);
- }
- }
- }
|