🐛 Fixes DI and lifetimes
This commit is contained in:
@@ -9,8 +9,7 @@ namespace DysonNetwork.Drive.Startup;
|
|||||||
public class BroadcastEventHandler(
|
public class BroadcastEventHandler(
|
||||||
INatsConnection nats,
|
INatsConnection nats,
|
||||||
ILogger<BroadcastEventHandler> logger,
|
ILogger<BroadcastEventHandler> logger,
|
||||||
FileService fs,
|
IServiceProvider serviceProvider
|
||||||
AppDatabase db
|
|
||||||
) : BackgroundService
|
) : BackgroundService
|
||||||
{
|
{
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@@ -24,6 +23,10 @@ public class BroadcastEventHandler(
|
|||||||
|
|
||||||
logger.LogInformation("Account deleted: {AccountId}", evt.AccountId);
|
logger.LogInformation("Account deleted: {AccountId}", evt.AccountId);
|
||||||
|
|
||||||
|
using var scope = serviceProvider.CreateScope();
|
||||||
|
var fs = scope.ServiceProvider.GetRequiredService<FileService>();
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
||||||
|
|
||||||
await using var transaction = await db.Database.BeginTransactionAsync(cancellationToken: stoppingToken);
|
await using var transaction = await db.Database.BeginTransactionAsync(cancellationToken: stoppingToken);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -4,6 +4,7 @@ using DysonNetwork.Pass.Startup;
|
|||||||
using DysonNetwork.Shared.Http;
|
using DysonNetwork.Shared.Http;
|
||||||
using DysonNetwork.Shared.PageData;
|
using DysonNetwork.Shared.PageData;
|
||||||
using DysonNetwork.Shared.Registry;
|
using DysonNetwork.Shared.Registry;
|
||||||
|
using DysonNetwork.Shared.Stream;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -16,6 +17,7 @@ builder.Services.AddAppMetrics();
|
|||||||
|
|
||||||
// Add application services
|
// Add application services
|
||||||
builder.Services.AddRegistryService(builder.Configuration);
|
builder.Services.AddRegistryService(builder.Configuration);
|
||||||
|
builder.Services.AddStreamConnection(builder.Configuration);
|
||||||
builder.Services.AddAppServices(builder.Configuration);
|
builder.Services.AddAppServices(builder.Configuration);
|
||||||
builder.Services.AddAppRateLimiting();
|
builder.Services.AddAppRateLimiting();
|
||||||
builder.Services.AddAppAuthentication();
|
builder.Services.AddAppAuthentication();
|
||||||
|
@@ -8,7 +8,7 @@ namespace DysonNetwork.Sphere.Startup;
|
|||||||
public class BroadcastEventHandler(
|
public class BroadcastEventHandler(
|
||||||
INatsConnection nats,
|
INatsConnection nats,
|
||||||
ILogger<BroadcastEventHandler> logger,
|
ILogger<BroadcastEventHandler> logger,
|
||||||
AppDatabase db
|
IServiceProvider serviceProvider
|
||||||
) : BackgroundService
|
) : BackgroundService
|
||||||
{
|
{
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@@ -22,7 +22,9 @@ public class BroadcastEventHandler(
|
|||||||
|
|
||||||
logger.LogInformation("Account deleted: {AccountId}", evt.AccountId);
|
logger.LogInformation("Account deleted: {AccountId}", evt.AccountId);
|
||||||
|
|
||||||
// TODO: Add empty realm, chat recycler in the db recycle
|
using var scope = serviceProvider.CreateScope();
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
||||||
|
|
||||||
await db.ChatMembers
|
await db.ChatMembers
|
||||||
.Where(m => m.AccountId == evt.AccountId)
|
.Where(m => m.AccountId == evt.AccountId)
|
||||||
.ExecuteDeleteAsync(cancellationToken: stoppingToken);
|
.ExecuteDeleteAsync(cancellationToken: stoppingToken);
|
||||||
|
Reference in New Issue
Block a user