51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using EntityFrameworkCore.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Text.Json.Serialization;
|
|
|
|
using EntityFrameworkCore.API.Controllers;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddControllers().AddJsonOptions(options =>
|
|
{
|
|
// IgnoreCycles prevents "System.Text.Json.JsonException: A possible object cycle was detected".
|
|
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
|
});
|
|
|
|
// Add services to the container.
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
|
|
var sqliteDatabaseName = builder.Configuration.GetConnectionString("SqliteDatabaseName");
|
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
|
var path = Environment.GetFolderPath(folder);
|
|
var dbPath = Path.Combine(path, sqliteDatabaseName);
|
|
var connectionString = $"Data Source={dbPath}";
|
|
|
|
builder.Services.AddDbContext<DeadBallZoneLeagueDbContext>(options => {
|
|
options.UseSqlite(connectionString)
|
|
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
|
.LogTo(Console.WriteLine, LogLevel.Information);
|
|
|
|
if (!builder.Environment.IsProduction())
|
|
{
|
|
// Do not allow this in Production.
|
|
options.EnableSensitiveDataLogging();
|
|
options.EnableDetailedErrors();
|
|
}
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|