12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.IdentityModel.Tokens;
- using MTWorkHR.Core.Email;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Core.IRepositories.Base;
- using MTWorkHR.Core.IRepositories;
- using MTWorkHR.Core.UnitOfWork;
- using MTWorkHR.Infrastructure.DBContext;
- using MTWorkHR.Infrastructure.EmailService;
- using MTWorkHR.Infrastructure.Repositories;
- using MTWorkHR.Infrastructure.UnitOfWorks;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MTWorkHR.Infrastructure.Entities;
- namespace MTWorkHR.Infrastructure
- {
- public static class InfrastructureServiceRegistration
- {
- public static IServiceCollection AddInfrastructureIdentityServices(this IServiceCollection services, AppSettingsConfiguration config)
- {
- services.AddSingleton(config);
- var vv = config.ConnectionStrings.MTWorkHRConnectionString;
- services.AddDbContext<HRDataContext>(options =>
- options.UseSqlServer(
- config.ConnectionStrings.MTWorkHRConnectionString //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
- ));
-
- services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();
-
- services.AddAuthentication(options => {
- options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // "bearer"
- options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
- }).AddJwtBearer(o=> o.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuerSigningKey = true,
- ValidateIssuer = true,
- ValidateAudience = true,
- ValidateLifetime = true,
- ClockSkew = TimeSpan.Zero,
- ValidIssuer = config.JwtSettings.Issuer,
- ValidAudience = config.JwtSettings.Audience,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.JwtSettings.SecretKey))
- }) ;
- services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
- services.AddScoped(typeof(IRepositoryLog<>), typeof(RepositoryLog<>));
- services.AddScoped(typeof(ICompanyRepository), typeof(CompanyRepository));
- services.AddScoped(typeof(IProjectRepository), typeof(ProjectRepository));
- services.AddScoped(typeof(ITaskStatusRepository), typeof(TaskStatusRepository));
- services.AddScoped(typeof(IUserTaskRepository), typeof(UserTaskRepository));
- services.AddScoped(typeof(IUserTaskAttachmentRepository), typeof(UserTaskAttachmentRepository));
- services.AddScoped(typeof(IUserTaskHistoryRepository), typeof(UserTaskHistoryRepository));
-
- services.AddScoped(typeof(ITeamRepository), typeof(TeamRepository));
- services.AddScoped(typeof(IMeetingRepository), typeof(MeetingRepository));
- services.AddScoped(typeof(IPermissionRepository), typeof(PermissionRepository));
- services.AddScoped(typeof(IRolePermissionRepository<RolePermission>), typeof(RolePermissionRepository));
- services.AddScoped(typeof(IUserRoleRepository<IdentityUserRole<string>>), typeof(UserRoleRepository));
- services.AddScoped<IUnitOfWork, UnitOfWork>();
- services.AddScoped<IUnitOfWorkLog, UnitOfWorkLog>();
- services.AddTransient<IMailSender, MailSender>();
- services.AddScoped<ApplicationUserManager>();
- services.AddScoped<GlobalInfo>();
- services.AddScoped<IEmployeeRepository, EmployeeRepository>();
- //services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
- return services;
- }
- }
- }
|