Files
MIESYSTEM/MieSystem/Program.cs
2025-12-26 22:27:20 -06:00

65 lines
2.2 KiB
C#

using System.Data;
using MicroORM;
using MicroORM.Interfaces;
using MieSystem.Data;
using MieSystem.Data.Interfaces;
using MieSystem.Data.Repositories;
using MieSystem.Services;
namespace MieSystem
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
builder.Services.AddSingleton<IDatabaseConnectionFactory, DatabaseConnectionFactory>();
/* Esto es lo nuevo */
builder.Services.AddSingleton<NpgsqlConnectionFactory>();
builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
// Delegate que consume el Repository<T>
builder.Services.AddScoped<Func<Task<IDbConnection>>>(sp =>
{
var factory = sp.GetRequiredService<NpgsqlConnectionFactory>();
return factory.CreateAsync;
});
builder.Services.AddScoped<ExpedienteService>();
builder.Services.AddScoped<AsistenciaService>();
/***********/
//builder.Services.AddScoped<IExpedienteRepository, ExpedienteRepository>();
builder.Services.AddScoped<IAsistenciaRepository, AsistenciaRepository>();
var app = builder.Build();
app.UseStaticFiles();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.Run();
}
}
}