using System.Configuration; using Microsoft.EntityFrameworkCore; namespace API.Workers; public abstract class BaseWorkerWithContext(IEnumerable? dependsOn = null) : BaseWorker(dependsOn) where T : DbContext { protected T DbContext = null!; public void SetScope(IServiceScope scope) => DbContext = scope.ServiceProvider.GetRequiredService(); /// Scope has not been set. public new Task DoWork() { if (DbContext is null) throw new ConfigurationErrorsException("Scope has not been set."); return base.DoWork(); } }