Refactor Worker to use IOptions for configuration
Replaced direct IConfiguration usage in Worker with IOptions<WorkerOptions> for strongly-typed configuration access. Updated delay interval assignment and added necessary namespace import.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost;
|
||||
|
||||
@@ -8,10 +9,10 @@ public class Worker : BackgroundService
|
||||
private readonly int _delayMilliseconds;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IConfiguration configuration, IServiceScopeFactory scopeFactory)
|
||||
public Worker(ILogger<Worker> logger, IOptions<WorkerOptions> options, IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_delayMilliseconds = Math.Max(1, configuration.GetValue("Worker:DelayMilliseconds", 1000));
|
||||
_delayMilliseconds = options.Value.DelayMilliseconds;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user