using Microsoft.EntityFrameworkCore; namespace API.Workers; public abstract class BaseWorkerWithContexts(IEnumerable? dependsOn = null) : BaseWorker(dependsOn) { /// /// Returns the context of requested type /// /// /// Type of /// Context in scope /// Scope not set protected T GetContext(IServiceScope scope) where T : DbContext { if (scope is not { } serviceScope) throw new Exception("Scope not set!"); return serviceScope.ServiceProvider.GetRequiredService(); } protected abstract void SetContexts(IServiceScope serviceScope); public new Task DoWork(IServiceScope serviceScope, Action? callback = null) { SetContexts(serviceScope); return base.DoWork(callback); } }