Commit 6628ae95 authored by hasan khaddour's avatar hasan khaddour

Restruture application layer.

parent be66bb06
using MediatR;
namespace PSManagement.Application.Abstraction.Messaging
{
public interface ICommand<out TResponse> : IRequest<TResponse>
{
}
}
using MediatR;
namespace PSManagement.Application.Abstraction.Messaging
{
public interface ICommandHandler<in TCommand, TResponse> : IRequestHandler<TCommand, TResponse>
where TCommand : ICommand<TResponse>
{
}
}
using MediatR;
namespace PSManagement.Application.Abstraction.Messaging
{
public interface IQuery<out TResponse> : IRequest<TResponse>
{
}
}
using MediatR;
namespace PSManagement.Application.Abstraction.Messaging
{
public interface IQueryHandler<in TQuery, TResponse> : IRequestHandler<TQuery, TResponse>
where TQuery : IQuery<TResponse>
{
}
}
using MediatR;
using PSManagement.Application.Abstraction.Messaging;
using PSManagement.Application.Common.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ValidationException = PSManagement.Application.Common.Exceptions.ValidationException;
namespace PSManagement.Application.Behaviors.ValidationBehavior
{
public sealed class ValidationBehavior<TRequest, TResponse> //: IPipelineBehavior<TRequest, TResponse>
// where TRequest : class, ICommand<TResponse>
{
//private readonly IEnumerable<IValidator<TRequest>> _validators;
//public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators) => _validators = validators;
//public async Task<TResponse> Handle(
// TRequest request,
// CancellationToken cancellationToken,
// RequestHandlerDelegate<TResponse> next)
//{
// if (!_validators.Any())
// {
// return await next();
// }
// var context = new ValidationContext<TRequest>(request);
// var errorsDictionary = _validators
// .Select(x => x.Validate(context))
// .SelectMany(x => x.Errors)
// .Where(x => x != null)
// .GroupBy(
// x => x.PropertyName,
// x => x.ErrorMessage,
// (propertyName, errorMessages) => new
// {
// Key = propertyName,
// Values = errorMessages.Distinct().ToArray()
// })
// .ToDictionary(x => x.Key, x => x.Values);
// if (errorsDictionary.Any())
// {
// throw new ValidationException(errorsDictionary);
// }
// return await next();
//}
}
}
using System;
namespace PSManagement.Application
{
public class Class1
{
}
}
using PSManagement.SharedKernel.DomainException;
using System.Collections.Generic;
namespace PSManagement.Application.Common.Exceptions
{
public sealed class ValidationException : BadRequestException
{
public ValidationException(Dictionary<string, string[]> errors)
: base("Validation errors occurred") =>
Errors = errors;
public Dictionary<string, string[]> Errors { get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application.Common.Services
{
public interface IDateTimeProvider
{
public DateTime UtcNow { get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application.Contracts.Authentication
{
public class AuthenticationResult
{
public Guid Id { get; set; }
public String Email { get; set; }
public String LastName { get; set; }
public String FirstName { get; set; }
public String Token { get; set; }
}
}
using System;
using System.Threading.Tasks;
namespace PSManagement.Application.Contracts.Authentication
{
public interface IAuthenticationService
{
public Task<AuthenticationResult> Login(String email , String password);
public Task<AuthenticationResult> Register(String email,String firstName ,String lastName, String password);
}
}
using System;
namespace PSManagement.Application.Contracts.Authentication
{
public interface IJwtTokenGenerator
{
public String GenerateToken(Guid id , String firstName , String lastName,String email );
}
}
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using PSManagement.Application.Contracts.Authentication;
namespace PSManagement.Application.DI namespace PSManagement.Application.DI
{ {
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Common\" />
<Folder Include="Services\" /> <Folder Include="Services\" />
<Folder Include="UseCases\" /> <Folder Include="UseCases\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup>
</Project> </Project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment