InfrastructureServiceRegistration.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.Configuration;
  3. using MTWorkHR.Application.Models.Email;
  4. using MTWorkHR.Infrastructure.EmailService;
  5. using MTWorkHR.Application.Logging;
  6. using MTWorkHR.Infrastructure.Logging;
  7. using MTWorkHR.Application.Services;
  8. using MTWorkHR.Core.Global;
  9. using Microsoft.AspNetCore.Identity;
  10. using Microsoft.EntityFrameworkCore;
  11. using MTWorkHR.Core.IRepositories.Base;
  12. using MTWorkHR.Core.IRepositories;
  13. using MTWorkHR.Core.UnitOfWork;
  14. using MTWorkHR.Identity.Entities;
  15. using MTWorkHR.Infrastructure.Data;
  16. using MTWorkHR.Infrastructure.Repositories;
  17. using MTWorkHR.Infrastructure.UnitOfWorks;
  18. namespace MTWorkHR.Infrastructure
  19. {
  20. public static class InfrastructureServiceRegistration
  21. {
  22. public static IServiceCollection AddInfrastructureServices (this IServiceCollection services, AppSettingsConfiguration configuration){
  23. services.AddDbContext<HRDataContext>(options => {
  24. options.UseSqlServer(configuration.ConnectionStrings.MTWorkHRConnectionString);
  25. });
  26. services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
  27. services.AddScoped(typeof(IRepositoryLog<>), typeof(RepositoryLog<>));
  28. services.AddScoped(typeof(ICompanyRepository), typeof(CompanyRepository));
  29. services.AddScoped(typeof(IPermissionRepository), typeof(PermissionRepository));
  30. services.AddScoped(typeof(IRolePermissionRepository<RolePermission>), typeof(RolePermissionRepository));
  31. services.AddScoped(typeof(IUserRoleRepository<IdentityUserRole<string>>), typeof(UserRoleRepository));
  32. services.AddScoped<IUnitOfWork, UnitOfWork>();
  33. services.AddScoped<IUnitOfWorkLog, UnitOfWorkLog>();
  34. services.AddScoped<ApplicationUserManager>();
  35. services.AddScoped<GlobalInfo>();
  36. services.AddScoped<IEmployeeRepository, EmployeeRepository>();
  37. services.AddTransient<IEmailSender, EmailSender>();
  38. services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
  39. return services;
  40. }
  41. }
  42. }