public class Worker : BackgroundService {
private readonly ILogger<Worker> logger;
private readonly WorkerOptions options;
public Worker(ILogger<Worker> logger, WorkerOptions options) {
this.logger = logger;
this.options = options;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
//do something that uses options
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(5000, stoppingToken);
}
}
}