refactor: replace internal UnitOfWork with NotificationUnitOfWork and NotificationBaseRepository

- Consolidate unit of work implementation with NotificationUnitOfWork.
- Refactor repositories to use NotificationBaseRepository for consistency.
- Simplify request handlers by removing IUnitOfWork dependency.
- Update related tests and service registration.
This commit is contained in:
Anatolii Grynchuk
2026-05-13 02:08:43 +03:00
parent b4d8497ea7
commit 50828d23ec
32 changed files with 276 additions and 186 deletions
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.Services.Logging;
using MediatR;
using Serilog;
@@ -8,14 +7,12 @@ namespace HrynCo.NotificationService.Services.Core;
public abstract class RequestHandler<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
protected RequestHandler(IContextualSerilogLogger<TRequest> logger, IUnitOfWork unitOfWork)
protected RequestHandler(IContextualSerilogLogger<TRequest> logger)
{
Logger = logger.Logger;
UnitOfWork = unitOfWork;
}
protected ILogger Logger { get; }
protected IUnitOfWork UnitOfWork { get; }
public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken)
{
@@ -23,4 +20,4 @@ public abstract class RequestHandler<TRequest, TResponse> : IRequestHandler<TReq
}
protected abstract Task<TResponse> DoOnHandle(TRequest request, CancellationToken cancellationToken);
}
}
@@ -14,9 +14,8 @@ internal sealed class CreateEmailChannelHandler
public CreateEmailChannelHandler(
IContextualSerilogLogger<CreateEmailChannelCommand> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -13,9 +13,8 @@ internal sealed class DeleteEmailChannelHandler
public DeleteEmailChannelHandler(
IContextualSerilogLogger<DeleteEmailChannelCommand> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Providers;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetEmailChannelHandler
public GetEmailChannelHandler(
IContextualSerilogLogger<GetEmailChannelQuery> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Providers;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetAllEmailChannelsHandler
public GetAllEmailChannelsHandler(
IContextualSerilogLogger<GetAllEmailChannelsQuery> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Providers;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetEmailChannelsHandler
public GetEmailChannelsHandler(
IContextualSerilogLogger<GetEmailChannelsQuery> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
using HrynCo.NotificationService.Services.Logging;
@@ -13,9 +12,8 @@ internal sealed class GetChannelUsageSummaryHandler
public GetChannelUsageSummaryHandler(
IContextualSerilogLogger<GetChannelUsageSummaryQuery> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channelsRepository)
: base(logger, unitOfWork)
: base(logger)
{
_channelsRepository = channelsRepository;
}
@@ -1,6 +1,5 @@
using System.Net;
using System.Net.Mail;
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Providers;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -17,10 +16,9 @@ internal sealed class SendEmailHandler
public SendEmailHandler(
IContextualSerilogLogger<SendEmailCommand> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels,
IEmailChannelUsageRepository usage)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
_usage = usage;
@@ -1,6 +1,5 @@
using System.Net;
using System.Net.Mail;
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.Services.Core;
using HrynCo.NotificationService.Services.Logging;
using static HrynCo.NotificationService.Services.Core.ServiceResultHelper;
@@ -11,9 +10,8 @@ internal sealed class TestSmtpHandler
: RequestHandler<TestSmtpCommand, ServiceResult<Unit>>
{
public TestSmtpHandler(
IContextualSerilogLogger<TestSmtpCommand> logger,
IUnitOfWork unitOfWork)
: base(logger, unitOfWork)
IContextualSerilogLogger<TestSmtpCommand> logger)
: base(logger)
{
}
@@ -13,9 +13,8 @@ internal sealed class UpdateEmailChannelHandler
public UpdateEmailChannelHandler(
IContextualSerilogLogger<UpdateEmailChannelCommand> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channels)
: base(logger, unitOfWork)
: base(logger)
{
_channels = channels;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class CreateEmailTemplateHandler
public CreateEmailTemplateHandler(
IContextualSerilogLogger<CreateEmailTemplateCommand> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}
@@ -13,9 +13,8 @@ internal sealed class DeleteEmailTemplateHandler
public DeleteEmailTemplateHandler(
IContextualSerilogLogger<DeleteEmailTemplateCommand> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetEmailTemplateHandler
public GetEmailTemplateHandler(
IContextualSerilogLogger<GetEmailTemplateQuery> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetAllEmailTemplatesHandler
public GetAllEmailTemplatesHandler(
IContextualSerilogLogger<GetAllEmailTemplatesQuery> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}
@@ -1,4 +1,3 @@
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.NotificationService.Services.Core;
@@ -14,9 +13,8 @@ internal sealed class GetEmailTemplatesHandler
public GetEmailTemplatesHandler(
IContextualSerilogLogger<GetEmailTemplatesQuery> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}
@@ -13,9 +13,8 @@ internal sealed class UpdateEmailTemplateHandler
public UpdateEmailTemplateHandler(
IContextualSerilogLogger<UpdateEmailTemplateCommand> logger,
IUnitOfWork unitOfWork,
IEmailTemplateRepository templates)
: base(logger, unitOfWork)
: base(logger)
{
_templates = templates;
}