Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using System.Text;
- using Microsoft.EntityFrameworkCore;
- using AutoMapper;
- using WebNET.Data.AutoMapper;
- using WebNET.Data;
- using WebNET.Source.Service;
- using WebNET.Source.Service.Interface;
- using Microsoft.IdentityModel.Tokens;
- WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
- /// Пациент
- builder.Services.AddScoped<IPatient, PatientService>();
- /// Специальности
- builder.Services.AddScoped<ISpeciality, SpecialityService>();
- /// Доктора
- builder.Services.AddScoped<IDoctorService, DoctorService>();
- builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
- .AddJwtBearer(options =>
- {
- options.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuer = true,
- ValidIssuer = Token.Issuer,
- ValidateAudience = true,
- ValidAudience = Token.Audience,
- ValidateLifetime = true,
- IssuerSigningKey = Token.GetSymmetricSecurityKey(),
- ValidateIssuerSigningKey = true,
- };
- });
- builder.Services.AddAutoMapper(typeof(MappingProfile));
- // Add services to the container.
- builder.Services.AddDbContext<ApplicationDBContext>(options =>
- options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
- builder.Services.AddControllers();
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSwaggerGen();
- WebApplication app = builder.Build();
- // Configure the HTTP request pipeline.
- if (app.Environment.IsDevelopment())
- {
- IApplicationBuilder applicationBuilder = app.UseSwagger();
- _ = app.UseSwaggerUI();
- }
- app.UseHttpsRedirection();
- //app.UseAuthentication();
- app.UseAuthorization();
- // НЕ ТРОГАТЬ!!!
- // ПАРСЕР!!!
- //using (var scope = app.Services.CreateScope())
- //{
- // var context = scope.ServiceProvider.GetRequiredService<ApplicationDBContext>();
- // DatabaseSeeder.SeedData(context);
- //}
- // ПЕРЕД СДАЧЕЙ СНЯТЬ КОММЕНЫ!!!
- app.MapControllers();
- app.Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement