-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (29 loc) · 1.19 KB
/
Program.cs
File metadata and controls
39 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using GameDevApi.Data;
using GameDevApi.Repository;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// 1. Configurar la conexión a la base de datos PostgreSQL.
// Lee la cadena de conexión desde appsettings.json.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString));
// 2. Registrar el Unit of Work para la inyección de dependencias.
// 'AddScoped' crea una instancia por cada petición HTTP, lo cual es ideal
// para que todos los repositorios en esa petición usen el mismo DbContext.
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
// 3. Añadir servicios estándar de API.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configurar el pipeline de HTTP.
if (app.Environment.IsDevelopment())
{
// Swagger es una herramienta genial para documentar y probar APIs.
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();