Commit 7e7abea2 authored by hasan khaddour's avatar hasan khaddour

refactor DI

parent 22786e30
...@@ -14,24 +14,28 @@ namespace PSManagement.Api.DI ...@@ -14,24 +14,28 @@ namespace PSManagement.Api.DI
{ {
public static IServiceCollection AddAPI(this IServiceCollection services) public static IServiceCollection AddAPI(this IServiceCollection services)
{ {
services.AddControllers();
services.AddApiSwagger(); services
.AddApiSwagger()
.AddApiCors()
.AddMapper()
.AddMyControllers();
services.AddApiCors(); return services;
}
services.AddScoped<Mapper>(); #region Configure controllers
private static IServiceCollection AddMyControllers(this IServiceCollection services) {
services.AddAutoMapper(cfg => {
cfg.AddProfile<CustomerMapperConfiguration>(); services
cfg.AddProfile<ProjectMapperConfiguration>(); .AddControllers()
cfg.AddProfile<MappersConfigurations>(); .AddApplicationPart(Presentation.AssemblyReference.Assembly);
});
return services; return services;
} }
#endregion Configure controllers
#region Api Docs Swagger
private static IServiceCollection AddApiSwagger(this IServiceCollection services) private static IServiceCollection AddApiSwagger(this IServiceCollection services)
{ {
...@@ -65,7 +69,9 @@ namespace PSManagement.Api.DI ...@@ -65,7 +69,9 @@ namespace PSManagement.Api.DI
return services; return services;
} }
#endregion Api Docs Swagger
#region Cors
private static IServiceCollection AddApiCors(this IServiceCollection services) private static IServiceCollection AddApiCors(this IServiceCollection services)
{ {
services.AddCors(options => services.AddCors(options =>
...@@ -83,6 +89,27 @@ namespace PSManagement.Api.DI ...@@ -83,6 +89,27 @@ namespace PSManagement.Api.DI
return services; return services;
} }
#endregion Cors
#region Mappers
private static IServiceCollection AddMapper(this IServiceCollection services ) {
services.AddScoped<Mapper>();
services.AddAutoMapper(cfg => {
cfg.AddProfile<CustomerMapperConfiguration>();
cfg.AddProfile<ProjectMapperConfiguration>();
cfg.AddProfile<MappersConfigurations>();
cfg.AddProfile<EmployeeMapperConfiguration>();
});
return services;
}
#endregion Mappers
} }
......
...@@ -4,22 +4,9 @@ using PSManagement.Application.Customers.Common; ...@@ -4,22 +4,9 @@ using PSManagement.Application.Customers.Common;
using PSManagement.Application.Customers.UseCases.Commands.AddContactInfo; using PSManagement.Application.Customers.UseCases.Commands.AddContactInfo;
using PSManagement.Application.Customers.UseCases.Commands.CreateCustomer; using PSManagement.Application.Customers.UseCases.Commands.CreateCustomer;
using PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer; using PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer;
using PSManagement.Application.Employees.Common;
using PSManagement.Application.Projects.Common;
using PSManagement.Application.Projects.UseCases.Commands.AddParticipant;
using PSManagement.Application.Projects.UseCases.Commands.AddProjectStep;
using PSManagement.Application.Projects.UseCases.Commands.ApproveProject;
using PSManagement.Application.Projects.UseCases.Commands.ChangeProjectTeamLeader;
using PSManagement.Application.Projects.UseCases.Commands.CreateProject;
using PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant;
using PSManagement.Application.Projects.UseCases.Queries.ListAllProject;
using PSManagement.Application.Tracks.Common;
using PSManagement.Contracts.Authentication; using PSManagement.Contracts.Authentication;
using PSManagement.Contracts.Customers.Requests; using PSManagement.Contracts.Customers.Requests;
using PSManagement.Contracts.Customers.Responses; using PSManagement.Contracts.Customers.Responses;
using PSManagement.Contracts.Projects.Requests;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Contracts.Tracks.Response;
using PSManagement.SharedKernel.Utilities; using PSManagement.SharedKernel.Utilities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -47,28 +34,4 @@ namespace PSManagement.Api.Mappers ...@@ -47,28 +34,4 @@ namespace PSManagement.Api.Mappers
CreateMap<AuthenticationResult,AuthenticationResponse>().ReverseMap(); CreateMap<AuthenticationResult,AuthenticationResponse>().ReverseMap();
} }
} }
public class ProjectMapperConfiguration : Profile
{
public ProjectMapperConfiguration()
{
CreateMap<CreateProjectRequest, CreateProjectCommand>().ReverseMap();
CreateMap<ListAllProjectsRequest, ListAllProjectsQuery>().ReverseMap();
CreateMap<ApproveProjectRequest, ApproveProjectCommand>().ReverseMap();
CreateMap<AddParticipantRequest, AddParticipantCommand>().ReverseMap();
CreateMap<AddProjectStepRequest, AddProjectStepCommand>().ReverseMap();
CreateMap<ChangeProjectTeamLeaderRequest, ChangeProjectTeamLeaderCommand>().ReverseMap();
CreateMap<RemoveParticipantRequest, RemoveParticipantCommand>().ReverseMap();
CreateMap<ProjectDTO,ProjectResponse>().ReverseMap();
CreateMap<GetProjectsByProjectManagerRequest,GetProjectsByFilterQuery>().ConstructUsing(
s => new GetProjectsByFilterQuery(null,null,null,null,s.ProjectManagerId,null,null,null)
);
CreateMap<EmployeeResponse, EmployeeDTO>().ReverseMap();
CreateMap<EmployeeParticipateResponse, EmployeeParticipateDTO>().ReverseMap();
CreateMap<TrackDTO, TrackResponse>().ReverseMap();
}
}
} }
using AutoMapper;
using PSManagement.Application.Employees.Common;
using PSManagement.Application.Projects.Common;
using PSManagement.Contracts.Projects.Response;
namespace PSManagement.Api.Mappers
{
public class EmployeeMapperConfiguration : Profile
{
public EmployeeMapperConfiguration()
{
CreateMap<EmployeeResponse, EmployeeDTO>().ReverseMap();
CreateMap<EmployeeParticipateResponse, EmployeeParticipateDTO>().ReverseMap();
}
}
}
using AutoMapper;
using PSManagement.Application.Projects.Common;
using PSManagement.Application.Projects.UseCases.Commands.AddParticipant;
using PSManagement.Application.Projects.UseCases.Commands.AddProjectStep;
using PSManagement.Application.Projects.UseCases.Commands.ApproveProject;
using PSManagement.Application.Projects.UseCases.Commands.ChangeProjectTeamLeader;
using PSManagement.Application.Projects.UseCases.Commands.CreateProject;
using PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant;
using PSManagement.Application.Projects.UseCases.Queries.ListAllProject;
using PSManagement.Application.Tracks.Common;
using PSManagement.Contracts.Projects.Requests;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Contracts.Tracks.Response;
namespace PSManagement.Api.Mappers
{
public class ProjectMapperConfiguration : Profile
{
public ProjectMapperConfiguration()
{
CreateMap<CreateProjectRequest, CreateProjectCommand>().ReverseMap();
CreateMap<ListAllProjectsRequest, ListAllProjectsQuery>().ReverseMap();
CreateMap<ApproveProjectRequest, ApproveProjectCommand>().ReverseMap();
CreateMap<AddParticipantRequest, AddParticipantCommand>().ReverseMap();
CreateMap<AddProjectStepRequest, AddProjectStepCommand>().ReverseMap();
CreateMap<ChangeProjectTeamLeaderRequest, ChangeProjectTeamLeaderCommand>().ReverseMap();
CreateMap<RemoveParticipantRequest, RemoveParticipantCommand>().ReverseMap();
CreateMap<ProjectDTO,ProjectResponse>().ReverseMap();
CreateMap<GetProjectsByProjectManagerRequest,GetProjectsByFilterQuery>().ConstructUsing(
s => new GetProjectsByFilterQuery(null,null,null,null,s.ProjectManagerId,null,null,null)
);
CreateMap<TrackDTO, TrackResponse>().ReverseMap();
}
}
}
...@@ -26,4 +26,8 @@ ...@@ -26,4 +26,8 @@
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" /> <ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Middleware\ExceptionHandling\" />
</ItemGroup>
</Project> </Project>
...@@ -31,16 +31,12 @@ namespace PSManagement.Api ...@@ -31,16 +31,12 @@ namespace PSManagement.Api
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// adding dependency injection // adding dependency injection
services services
.AddAPI() .AddAPI()
.AddPresentation() .AddPresentation()
.AddApplication() .AddApplication()
.AddPersistence(Configuration) .AddPersistence(Configuration)
.AddInfrastructure(Configuration); .AddInfrastructure(Configuration);
services
.AddControllers()
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
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