PalacePal/Pal.Client/Floors/Tasks/DbTask.cs

30 lines
781 B
C#
Raw Normal View History

2023-02-18 20:12:36 +00:00
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Pal.Client.Database;
namespace Pal.Client.Floors.Tasks
{
internal abstract class DbTask
{
private readonly IServiceScopeFactory _serviceScopeFactory;
protected DbTask(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
}
public void Start()
{
Task.Run(() =>
{
using var scope = _serviceScopeFactory.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<PalClientContext>();
Run(dbContext);
});
}
protected abstract void Run(PalClientContext dbContext);
}
}