- Domain layer: Lesson entity, GermanWord value object, repository interfaces - Application layer: CQRS commands, DTOs with mapping - Infrastructure layer: EF Core with SQLite, LessonRepository - Presentation layer: Minimal API endpoints for lessons CRUD Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
99 lines
3 KiB
C#
99 lines
3 KiB
C#
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<AppDbContext>(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<ILessonRepository, LessonRepository>();
|
|
|
|
// ============================================
|
|
// APPLICATION LAYER - Use Cases & Services
|
|
// ============================================
|
|
|
|
// Register command handlers
|
|
builder.Services.AddScoped<ICommandHandler<CreateLessonCommand, LessonDto>, 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<AppDbContext>();
|
|
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);
|
|
}
|