From 15ecc6e1d5aa7fc0d6c3c3ba6c169a5a7494e9c9 Mon Sep 17 00:00:00 2001 From: Magnus Sandgren <5285192+MagnusSandgren@users.noreply.github.com> Date: Sat, 12 Oct 2024 00:24:32 +0200 Subject: [PATCH] WIP --- .../Behaviours/IdempotentNotificationHandler.cs | 14 +++++++++----- .../Persistence/DialogDbContext.cs | 3 +++ src/Digdir.Domain.Dialogporten.WebApi/Program.cs | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/IdempotentNotificationHandler.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/IdempotentNotificationHandler.cs index 5a4f19fec..6b7130bec 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/IdempotentNotificationHandler.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/IdempotentNotificationHandler.cs @@ -14,9 +14,7 @@ public interface IIdempotentNotificationContext public readonly record struct NotificationAcknowledgementPart(string NotificationHandler, Guid EventId); -internal sealed class IdempotentNotificationHandler( - INotificationHandler decorated, - IIdempotentNotificationContext repository) : +internal sealed class IdempotentNotificationHandler : INotificationHandler, // We need to manually register this NotificationHandler because // it should decorate all INotificationHandler @@ -24,8 +22,14 @@ internal sealed class IdempotentNotificationHandler( IIgnoreOnAssemblyScan where TNotification : IDomainEvent { - private readonly INotificationHandler _decorated = decorated ?? throw new ArgumentNullException(nameof(decorated)); - private readonly IIdempotentNotificationContext _repository = repository ?? throw new ArgumentNullException(nameof(repository)); + private readonly INotificationHandler _decorated; + private readonly IIdempotentNotificationContext _repository; + + public IdempotentNotificationHandler(INotificationHandler decorated, IIdempotentNotificationContext repository) + { + _decorated = decorated ?? throw new ArgumentNullException(nameof(decorated)); + _repository = repository ?? throw new ArgumentNullException(nameof(repository)); + } public async Task Handle(TNotification notification, CancellationToken cancellationToken) { diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs index 553ca5a42..84b028fed 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs @@ -117,6 +117,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .AddTransactionalOutboxEntities(builder => { builder.ToTable($"MassTransit{builder.Metadata.GetTableName()}"); + + // We can remove the code below when the following commit is in a MassTransit release we are using. + // https://github.com/MassTransit/MassTransit/commit/755b267a53c3e5fcdc9dcc0bbfda68a70aaf6bf4 if (builder is not EntityTypeBuilder outboxMessageBuilder) { return; diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index 1b1ac0267..f6d179cba 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -52,7 +52,7 @@ static void BuildAndRun(string[] args) { var builder = WebApplication.CreateBuilder(args); - builder.Host.UseDefaultServiceProvider(options => options.ValidateScopes = false); + builder.Host.UseSerilog((context, services, configuration) => configuration .MinimumLevel.Warning() .ReadFrom.Configuration(context.Configuration) @@ -139,8 +139,6 @@ static void BuildAndRun(string[] args) predicate: localDevelopmentSettings.DisableAuth) .ReplaceSingleton( predicate: localDevelopmentSettings.DisableAuth); - // .AddHostedService< - // OutboxScheduler>(predicate: !localDevelopmentSettings.DisableShortCircuitOutboxDispatcher); } var app = builder.Build();