Actions initial commit
Some checks failed
Docker Image CI / build (push) Has been cancelled

This commit is contained in:
2025-10-16 02:52:04 +02:00
parent 13fb917c5d
commit 53276e858b
36 changed files with 1013 additions and 169 deletions

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
namespace API.Workers;
public abstract class BaseWorkerWithContexts(IEnumerable<BaseWorker>? dependsOn = null) : BaseWorker(dependsOn)
{
/// <summary>
/// Returns the context of requested type <typeparamref name="T"/>
/// </summary>
/// <param name="scope"></param>
/// <typeparam name="T">Type of <see cref="DbContext"/></typeparam>
/// <returns>Context in scope</returns>
/// <exception cref="Exception">Scope not set</exception>
protected T GetContext<T>(IServiceScope scope) where T : DbContext
{
if (scope is not { } serviceScope)
throw new Exception("Scope not set!");
return serviceScope.ServiceProvider.GetRequiredService<T>();
}
protected abstract void SetContexts(IServiceScope serviceScope);
public new Task<BaseWorker[]> DoWork(IServiceScope serviceScope, Action? callback = null)
{
SetContexts(serviceScope);
return base.DoWork(callback);
}
}