Advertisement
Tark_Wight

ProgCS

Jan 7th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. using Microsoft.AspNetCore.Authentication.JwtBearer;
  2. using System.Text;
  3. using Microsoft.EntityFrameworkCore;
  4. using AutoMapper;
  5. using WebNET.Data.AutoMapper;
  6. using WebNET.Data;
  7. using WebNET.Source.Service;
  8. using WebNET.Source.Service.Interface;
  9. using Microsoft.IdentityModel.Tokens;
  10.  
  11. WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
  12.  
  13. /// Пациент
  14. builder.Services.AddScoped<IPatient, PatientService>();
  15.  
  16. /// Специальности
  17. builder.Services.AddScoped<ISpeciality, SpecialityService>();
  18.  
  19. /// Доктора
  20. builder.Services.AddScoped<IDoctorService, DoctorService>();
  21.  
  22.  
  23. builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
  24. .AddJwtBearer(options =>
  25. {
  26. options.TokenValidationParameters = new TokenValidationParameters
  27. {
  28. ValidateIssuer = true,
  29. ValidIssuer = Token.Issuer,
  30. ValidateAudience = true,
  31. ValidAudience = Token.Audience,
  32. ValidateLifetime = true,
  33. IssuerSigningKey = Token.GetSymmetricSecurityKey(),
  34. ValidateIssuerSigningKey = true,
  35. };
  36. });
  37.  
  38.  
  39. builder.Services.AddAutoMapper(typeof(MappingProfile));
  40.  
  41.  
  42. // Add services to the container.
  43. builder.Services.AddDbContext<ApplicationDBContext>(options =>
  44. options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
  45.  
  46. builder.Services.AddControllers();
  47. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  48. builder.Services.AddEndpointsApiExplorer();
  49. builder.Services.AddSwaggerGen();
  50.  
  51. WebApplication app = builder.Build();
  52.  
  53. // Configure the HTTP request pipeline.
  54. if (app.Environment.IsDevelopment())
  55. {
  56. IApplicationBuilder applicationBuilder = app.UseSwagger();
  57. _ = app.UseSwaggerUI();
  58. }
  59.  
  60. app.UseHttpsRedirection();
  61.  
  62. //app.UseAuthentication();
  63.  
  64. app.UseAuthorization();
  65.  
  66. // НЕ ТРОГАТЬ!!!
  67. // ПАРСЕР!!!
  68. //using (var scope = app.Services.CreateScope())
  69. //{
  70. // var context = scope.ServiceProvider.GetRequiredService<ApplicationDBContext>();
  71. // DatabaseSeeder.SeedData(context);
  72. //}
  73. // ПЕРЕД СДАЧЕЙ СНЯТЬ КОММЕНЫ!!!
  74.  
  75. app.MapControllers();
  76.  
  77. app.Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement