/
Extrap
/
Network_technologies_Project
Обзор
Документация
Войти
/
Extrap
/
Network_technologies_Project
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Project/Program.cs
73 строки
2 KB
Extrap
Конечка (хз, но для воскресенья да)
21 дек 2025, 22:48
21 дек 2025, 22:48
1c6535d
Код
Авторство
О чём код?
using Microsoft.EntityFrameworkCore; using Project.Data; using Project.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using System.Text; using Project.Models; using Project.Interfaces; using Project.Repositories; var builder = WebApplication.CreateBuilder(args); // ��������� �� builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); // ��������� JWT var jwtKey = builder.Configuration["Jwt:Key"] ?? throw new ArgumentNullException("Jwt:Key not found"); var key = Encoding.UTF8.GetBytes(jwtKey); builder.Services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = true, ValidateAudience = true, ValidIssuer = builder.Configuration["Jwt:Issuer"], ValidAudience = builder.Configuration["Jwt:Audience"], ClockSkew = TimeSpan.Zero }; }); // ����������� �������� � ������������ builder.Services.AddScoped<JwtService>(); builder.Services.AddScoped<IUserRepository, UserRepository>(); builder.Services.AddScoped<IWorkoutRepository, WorkoutRepository>(); builder.Services.AddScoped<ReportService>(); // ����������� builder.Services.AddControllers() .AddJsonOptions(options => { // ��������� ���������� Enum ��� ������, � �� ����� options.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); }); var app = builder.Build(); // Middleware app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); // ���������� ��������� ������� �� ������� ���������� if (app.Environment.IsDevelopment()) { using var scope = app.Services.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); dbContext.Database.EnsureCreated(); //TestDataSeeder.SeedTestData(dbContext); } app.Run();