mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
24 lines
771 B
C#
24 lines
771 B
C#
using System.Configuration;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace API.Workers;
|
|
|
|
public abstract class BaseWorkerWithContext<T>(IEnumerable<BaseWorker>? dependsOn = null) : BaseWorker(dependsOn) where T : DbContext
|
|
{
|
|
protected T DbContext = null!;
|
|
private IServiceScope? _scope;
|
|
|
|
public void SetScope(IServiceScope scope)
|
|
{
|
|
this._scope = scope;
|
|
this.DbContext = scope.ServiceProvider.GetRequiredService<T>();
|
|
}
|
|
|
|
/// <exception cref="ConfigurationErrorsException">Scope has not been set. <see cref="SetScope"/></exception>
|
|
public new Task<BaseWorker[]> DoWork()
|
|
{
|
|
if (DbContext is null)
|
|
throw new ConfigurationErrorsException("Scope has not been set.");
|
|
return base.DoWork();
|
|
}
|
|
} |