InfrastructureServiceRegistration.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Microsoft.AspNetCore.Authentication.JwtBearer;
  2. using Microsoft.AspNetCore.Identity;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.IdentityModel.Tokens;
  7. using MTWorkHR.Core.Email;
  8. using MTWorkHR.Core.Global;
  9. using MTWorkHR.Core.IRepositories.Base;
  10. using MTWorkHR.Core.IRepositories;
  11. using MTWorkHR.Core.UnitOfWork;
  12. using MTWorkHR.Infrastructure.DBContext;
  13. using MTWorkHR.Infrastructure.EmailService;
  14. using MTWorkHR.Infrastructure.Repositories;
  15. using MTWorkHR.Infrastructure.UnitOfWorks;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using MTWorkHR.Infrastructure.Entities;
  22. namespace MTWorkHR.Infrastructure
  23. {
  24. public static class InfrastructureServiceRegistration
  25. {
  26. public static IServiceCollection AddInfrastructureIdentityServices(this IServiceCollection services, AppSettingsConfiguration config)
  27. {
  28. services.AddSingleton(config);
  29. var vv = config.ConnectionStrings.MTWorkHRConnectionString;
  30. services.AddDbContext<HRDataContext>(options =>
  31. options.UseSqlServer(
  32. config.ConnectionStrings.MTWorkHRConnectionString //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
  33. ));
  34. services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();
  35. services.AddAuthentication(options => {
  36. options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // "bearer"
  37. options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  38. }).AddJwtBearer(o=> o.TokenValidationParameters = new TokenValidationParameters
  39. {
  40. ValidateIssuerSigningKey = true,
  41. ValidateIssuer = true,
  42. ValidateAudience = true,
  43. ValidateLifetime = true,
  44. ClockSkew = TimeSpan.Zero,
  45. ValidIssuer = config.JwtSettings.Issuer,
  46. ValidAudience = config.JwtSettings.Audience,
  47. IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.JwtSettings.SecretKey))
  48. }) ;
  49. services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
  50. services.AddScoped(typeof(IRepositoryLog<>), typeof(RepositoryLog<>));
  51. services.AddScoped(typeof(ICompanyRepository), typeof(CompanyRepository));
  52. services.AddScoped(typeof(IProjectRepository), typeof(ProjectRepository));
  53. services.AddScoped(typeof(ITaskStatusRepository), typeof(TaskStatusRepository));
  54. services.AddScoped(typeof(IUserTaskRepository), typeof(UserTaskRepository));
  55. services.AddScoped(typeof(IUserTaskAttachmentRepository), typeof(UserTaskAttachmentRepository));
  56. services.AddScoped(typeof(IUserTaskHistoryRepository), typeof(UserTaskHistoryRepository));
  57. services.AddScoped(typeof(ITeamRepository), typeof(TeamRepository));
  58. services.AddScoped(typeof(IMeetingRepository), typeof(MeetingRepository));
  59. services.AddScoped(typeof(IAttendanceRepository), typeof(AttendanceRepository));
  60. services.AddScoped(typeof(IOrderAllocationRepository), typeof(OrderAllocationRepository));
  61. services.AddScoped(typeof(IOrderRequestRepository), typeof(OrderRequestRepository));
  62. services.AddScoped(typeof(IOrderTypeRepository), typeof(OrderTypeRepository));
  63. services.AddScoped(typeof(ILeaveTypeRepository), typeof(LeaveTypeRepository));
  64. services.AddScoped(typeof(ICountryLookupRepository), typeof(CountryLookupRepository));
  65. services.AddScoped(typeof(IIndustryRepository), typeof(IndustryRepository));
  66. services.AddScoped(typeof(IJobTitleRepository), typeof(JobTitleRepository));
  67. services.AddScoped(typeof(IQualificationRepository), typeof(QualificationRepository));
  68. services.AddScoped(typeof(IUniversityRepository), typeof(UniversityRepository));
  69. services.AddScoped(typeof(ILoginOTPRepository), typeof(LoginOTPRepository));
  70. services.AddScoped(typeof(ICityRepository), typeof(CityRepository));
  71. services.AddScoped(typeof(IPermissionRepository), typeof(PermissionRepository));
  72. services.AddScoped(typeof(IRolePermissionRepository<RolePermission>), typeof(RolePermissionRepository));
  73. services.AddScoped(typeof(IUserRoleRepository<IdentityUserRole<string>>), typeof(UserRoleRepository));
  74. services.AddScoped<IUnitOfWork, UnitOfWork>();
  75. services.AddScoped<IUnitOfWorkLog, UnitOfWorkLog>();
  76. services.AddTransient<IMailSender, MailSender>();
  77. services.AddScoped<ApplicationUserManager>();
  78. services.AddScoped<GlobalInfo>();
  79. services.AddScoped<IEmployeeRepository, EmployeeRepository>();
  80. //services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
  81. return services;
  82. }
  83. }
  84. }