Files
Anatolii Grynchuk ee4c988a0d refactor: replace local dal abstractions with hrynco-ef packages
Remove duplicate IEntity, Entity, ITransaction, IUnitOfWork, EfRepository,
EfUnitOfWork, EfTransactionAdapter — now consumed from HrynCo.DAL.Abstract
and HrynCo.DAL.EF packages (1.0.1).

Ref: IT-0
2026-05-05 20:39:06 +03:00

28 lines
952 B
C#

using HrynCo.Common;
using HrynCo.DAL.Abstract;
using MediatR;
namespace HrynCo.NotificationService.Services.Behaviors;
public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
private readonly IUnitOfWork _unitOfWork;
private readonly IProfiler _profiler;
public TransactionBehavior(IUnitOfWork unitOfWork, IProfiler profiler)
{
_unitOfWork = unitOfWork;
_profiler = profiler;
}
public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) =>
_profiler.MeasureExecutionAsync(
() => _unitOfWork.ExecuteInTransactionAsync(async () =>
{
TResponse response = await next();
await _unitOfWork.SaveChangesAsync(cancellationToken);
return response;
}),
typeof(TRequest).Name);
}