Files

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-12-11 14:04:39 +08:00
using Microsoft.EntityFrameworkCore;
using MySQLAccess.PGModels;
using Npgsql.PostgresTypes;
using .Services;
namespace
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMemoryCache();
//AddDbContext默认已经将DbContext注册为Scoped生命周期再次显式注册会导致冲突
builder.Services.AddDbContext<PostgresContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("PGSqlStr"));
});
builder.Services.AddHostedService<MyTimer>();
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
}
}