DemO/DEMO/Program.cs

35 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// это главный файл, тут все начинается
using DEMO.Data; // база данных
using Microsoft.EntityFrameworkCore; // чтоб работать с базой
var builder = WebApplication.CreateBuilder(args);
// говорю что у меня есть контроллеры (api)
builder.Services.AddControllers();
// подключаю базу данных
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection"))); // беру строку из настроек
builder.Services.AddOpenApi(); // для проверки api
var app = builder.Build(); // строю программу
// в режиме разработки показываю api
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection(); // всегда https
app.UseDefaultFiles(); // чтоб открывался index.html сам
app.UseStaticFiles(); // чтоб отдавать файлы из wwwroot
app.UseAuthorization(); // проверка прав (пока простая)
app.MapControllers(); // включаю все контроллеры
app.Run(); // запускаю, поехали