Refactored event service injection
This commit is contained in:
@@ -20,7 +20,7 @@ public sealed class LateProjectEvent : IEvent
|
||||
}
|
||||
|
||||
public sealed class LateProjectEventHandler(IDbContextFactory<ApplicationDbContext> contextFactory,
|
||||
ICommunicationsService service) : INotificationHandler<LateProjectEvent>
|
||||
IServiceProvider provider) : INotificationHandler<LateProjectEvent>
|
||||
{
|
||||
readonly int lateDays = 3;
|
||||
|
||||
@@ -28,6 +28,9 @@ public sealed class LateProjectEventHandler(IDbContextFactory<ApplicationDbConte
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var scope = provider.CreateScope().ServiceProvider;
|
||||
var service = scope.GetRequiredService<ICommunicationsService>();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var overdueCutoff = lateDays > 0 ? now.AddDays(-lateDays) : now;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user