From 5ab2d29aac1498fadbcce555a2165f10bfe527d4 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Tue, 2 Jun 2026 00:03:01 +0200 Subject: [PATCH] Used scope to inject services --- .../PayfastPaymentConfirmationReceivedEventHandler.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/LiteCharms.Features.MidrandBooks/Payments/Events/Handlers/PayfastPaymentConfirmationReceivedEventHandler.cs b/LiteCharms.Features.MidrandBooks/Payments/Events/Handlers/PayfastPaymentConfirmationReceivedEventHandler.cs index 96682ed..66ba389 100644 --- a/LiteCharms.Features.MidrandBooks/Payments/Events/Handlers/PayfastPaymentConfirmationReceivedEventHandler.cs +++ b/LiteCharms.Features.MidrandBooks/Payments/Events/Handlers/PayfastPaymentConfirmationReceivedEventHandler.cs @@ -6,12 +6,14 @@ namespace LiteCharms.Features.MidrandBooks.Payments.Events.Handlers; public sealed class PayfastPaymentConfirmationReceivedEventHandler(IServiceProvider services, ILogger logger) : INotificationHandler { - private readonly PaymentService paymentService = services.GetRequiredService(); - private readonly OrderService orderService = services.GetRequiredService(); - private readonly HashService hashService = services.GetRequiredService(); - public async ValueTask Handle(PayfastPaymentConfirmationReceivedEvent notification, CancellationToken cancellationToken) { + await using var scope = services.CreateAsyncScope(); + + PaymentService paymentService = scope.ServiceProvider.GetRequiredService(); + OrderService orderService = scope.ServiceProvider.GetRequiredService(); + HashService hashService = scope.ServiceProvider.GetRequiredService(); + var hashResult = hashService.DecodeLongIdHash(notification.Payload?.MPaymentId!); if (hashResult.IsFailed) { -- 2.47.3