a03d2269a6
- ServiceResult<T>, ServiceError, ServiceErrorCode, Unit, ServiceResultHelper in Services/Core - RequestHandler<TRequest, TResponse> base class (MediatR-adapted, DoOnHandle pattern) - EmailTemplate handlers: Create, Update, Delete, Get, GetByService - EmailChannel handlers: Create, Update, Delete, Get, GetByService Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
25 lines
830 B
C#
25 lines
830 B
C#
using HrynCo.NotificationService.DAL.Abstract;
|
|
using HrynCo.NotificationService.Services.Logging;
|
|
using MediatR;
|
|
using Serilog;
|
|
|
|
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)
|
|
{
|
|
Logger = logger.Logger;
|
|
UnitOfWork = unitOfWork;
|
|
}
|
|
|
|
protected ILogger Logger { get; }
|
|
protected IUnitOfWork UnitOfWork { get; }
|
|
|
|
public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken) =>
|
|
DoOnHandle(request, cancellationToken);
|
|
|
|
protected abstract Task<TResponse> DoOnHandle(TRequest request, CancellationToken cancellationToken);
|
|
}
|