using GermanApp.Application.DTOs; using GermanApp.Application.UseCases.Commands; using GermanApp.Domain.Interfaces; using GermanApp.Infrastructure.Data.DbContext; using GermanApp.Infrastructure.Data.Repositories; using GermanApp.Presentation.Endpoints; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); // Add services to the container. // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); // ============================================ // INFRASTRUCTURE LAYER - Database & External Services // ============================================ // Add DbContext with SQLite (can be changed to SQL Server, PostgreSQL, etc.) builder.Services.AddDbContext(options => { // Using SQLite for development - configure in appsettings.json for production options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection") ?? "Data Source=germanapp.db"); // Enable sensitive data logging in development if (builder.Environment.IsDevelopment()) { options.EnableSensitiveDataLogging(); options.EnableDetailedErrors(); } }); // Register repositories (Infrastructure implementations of Domain interfaces) builder.Services.AddScoped(); // ============================================ // APPLICATION LAYER - Use Cases & Services // ============================================ // Register command handlers builder.Services.AddScoped, CreateLessonCommandHandler>(); // ============================================ // PRESENTATION LAYER - API // ============================================ // Add services for Minimal APIs builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); app.UseSwagger(); app.UseSwaggerUI(); } // Initialize database (in development) if (app.Environment.IsDevelopment()) { using var scope = app.Services.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); dbContext.Database.EnsureCreated(); } // Map Clean Architecture endpoints app.MapLessonsEndpoints(); // Keep original WeatherForecast endpoint for reference app.MapGet("/weatherforecast", () => { var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; var forecast = Enumerable.Range(1, 5).Select(index => new WeatherForecast ( DateOnly.FromDateTime(DateTime.Now.AddDays(index)), Random.Shared.Next(-20, 55), summaries[Random.Shared.Next(summaries.Length)] )) .ToArray(); return forecast; }) .WithName("GetWeatherForecast"); app.Run(); // Existing record for reference record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) { public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); }