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(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("PGSqlStr")); }); builder.Services.AddHostedService(); // 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(); } } }