InfrastructureServiceRegistration.cs 2.0 KB

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