docker files fixes from liaqat

This commit is contained in:
alirehmani
2024-05-03 16:39:25 +05:00
commit 464a8730e8
587 changed files with 44288 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
using MediatR;
namespace Managing.Application.Shared.Behaviours
{
public interface IUnhandledExceptionBehaviour<TRequest, TResponse>
{
Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next);
}
}

View File

@@ -0,0 +1,31 @@
using MediatR;
using Microsoft.Extensions.Logging;
namespace Managing.Application.Shared.Behaviours
{
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IUnhandledExceptionBehaviour<TRequest, TResponse>
{
private readonly ILogger<TRequest> logger;
public UnhandledExceptionBehaviour(ILogger<TRequest> logger)
{
this.logger = logger;
}
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (Exception ex)
{
var requestName = typeof(TRequest).Name;
logger.LogError(ex, $"Unhandled Exception for Request {requestName} {request}");
throw;
}
}
}
}

View File

@@ -0,0 +1,29 @@
using FluentValidation;
using MediatR;
namespace Managing.Application.Shared.Behaviours
{
public class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IEnumerable<IValidator<TRequest>> validators;
public ValidationBehaviour(IEnumerable<IValidator<TRequest>> validators)
{
this.validators = validators;
}
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
if (validators.Any())
{
var context = new ValidationContext<TRequest>(request);
var validationResults = await Task.WhenAll(validators.Select(v => v.ValidateAsync(context, cancellationToken)));
var failures = validationResults.SelectMany(r => r.Errors).Where(f => f != null).ToList();
if (failures.Count != 0) throw new ValidationException(failures);
}
return await next();
}
}
}