Files
2025-12-11 14:04:39 +08:00

45 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
}
}
}