PersistenceServiceRegistration.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.EntityFrameworkCore;
  3. using MTWorkHR.Infrastructure.Data;
  4. using Microsoft.Extensions.Configuration;
  5. using MTWorkHR.Core.IRepositories.Base;
  6. using MTWorkHR.Infrastructure.Repositories;
  7. using MTWorkHR.Core.IRepositories;
  8. using MTWorkHR.Identity.Models;
  9. using Microsoft.AspNetCore.Identity;
  10. using MTWorkHR.Core.UnitOfWork;
  11. using MTWorkHR.Infrastructure.UnitOfWorks;
  12. using MTWorkHR.Core.Global;
  13. namespace MTWorkHR.Infrastructure
  14. {
  15. public static class PersistenceServiceRegistration
  16. {
  17. public static IServiceCollection AddPersistenceServices (this IServiceCollection services, IConfiguration configuration){
  18. services.AddDbContext<HRDataContext>(options => {
  19. options.UseSqlServer(configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
  20. });
  21. services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
  22. services.AddScoped(typeof(IRepositoryLog<>), typeof(RepositoryLog<>));
  23. services.AddScoped(typeof(IPermissionRepository), typeof(PermissionRepository));
  24. services.AddScoped(typeof(IRolePermissionRepository<RolePermission>), typeof(RolePermissionRepository));
  25. services.AddScoped(typeof(IUserRoleRepository<IdentityUserRole<string>>), typeof(UserRoleRepository));
  26. services.AddScoped<IUnitOfWork, UnitOfWork>();
  27. services.AddScoped<IUnitOfWorkLog, UnitOfWorkLog>();
  28. services.AddScoped<ApplicationUserManager>();
  29. services.AddScoped<GlobalInfo>();
  30. services.AddScoped<IEmployeeRepository, EmployeeRepository>();
  31. return services;
  32. }
  33. }
  34. }