升级.net8暂存

This commit is contained in:
dell
2024-11-14 09:01:37 +08:00
parent 08a59bd2a3
commit 48e9e27fa0
110 changed files with 11291 additions and 4541 deletions

View File

@ -2,10 +2,14 @@ using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using HT.Cloud.Code;
using HT.Cloud.Service;
@ -18,7 +22,8 @@ namespace HT.Cloud.Web
{
public class Startup : DefaultStartUp
{
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env)
private List<string> _plugins = new List<string> { "WaterCloud.Service" };
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env)
{
}
@ -48,8 +53,8 @@ namespace HT.Cloud.Web
});
base.ConfigureServices(services);
services.AddDefaultSwaggerGen(Assembly.GetExecutingAssembly().GetName().Name)
.AddSqlSugar()
services.AddDefaultSwaggerGen(Assembly.GetExecutingAssembly().GetName().Name)
.AddSqlSugar()
.AddQuartz()
.ReviseSuperSysem()
.AddEventBus()
@ -63,8 +68,43 @@ namespace HT.Cloud.Web
options.KeepAliveInterval = TimeSpan.FromMinutes(2);
});
services.AddDefaultAPI();
services.AddDefaultMVC().AddNewtonsoftJson(options =>
{
services.AddDefaultMVC()
.ConfigureApplicationPartManager(apm => {
var plugDir = Directory.GetCurrentDirectory() + "/Plugins";
if (!Directory.Exists(plugDir))
Directory.CreateDirectory(plugDir);
base.ConfigureServices(services);
var paths = Directory.GetDirectories(plugDir);
var hostAssembly = Assembly.GetExecutingAssembly();
foreach (var path in paths)
{
var name = Path.GetFileName(path);
var fn = path + "/" + name + ".dll";
if (File.Exists(fn))
{
var addInAssembly = Assembly.LoadFrom(fn);
var controllerAssemblyPart = new AssemblyPart(addInAssembly);
apm.ApplicationParts.Add(controllerAssemblyPart);
//开始判断是不是有razor页面
fn = path + "/" + name + ".Views.dll";
if (File.Exists(fn))
{
var addInAssemblyView = Assembly.LoadFrom(fn);
var viewAssemblyPart = new CompiledRazorAssemblyPart(addInAssemblyView);
apm.ApplicationParts.Add(viewAssemblyPart);
}
else
{
var viewAssemblyPart = new CompiledRazorAssemblyPart(addInAssembly);
apm.ApplicationParts.Add(viewAssemblyPart);
}
_plugins.Add(path);
}
}
_plugins = _plugins.Distinct().ToList();
})
.AddNewtonsoftJson(options =>
{
// 返回数据首字母不小写CamelCasePropertyNamesContractResolver是小写
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
@ -73,16 +113,17 @@ namespace HT.Cloud.Web
services.AddRazorPages().AddRazorRuntimeCompilation();
//调试前端可更新
services.AddControllersWithViews().AddRazorRuntimeCompilation();
//清理缓存
//CacheHelper.FlushAllAsync().GetAwaiter().GetResult();
}
services.AddRazorPages();
//清理缓存
//CacheHelper.FlushAllAsync().GetAwaiter().GetResult();
}
//AutoFac注入
public void ConfigureContainer(ContainerBuilder builder)
//AutoFac注入
public void ConfigureContainer(ContainerBuilder builder)
{
AutofacConfigureContainer(builder, default, typeof(Controller), typeof(IDenpendency), typeof(Program));
AutofacConfigureContainer(builder, default, typeof(ControllerBase), typeof(IDenpendency), typeof(Program));
}
AutofacConfigureContainer(builder, _plugins, typeof(Controller), typeof(IDenpendency), typeof(Program));
AutofacConfigureContainer(builder, _plugins, typeof(ControllerBase), typeof(IDenpendency), typeof(Program));
}
public override void Configure(IApplicationBuilder app)
{
@ -96,7 +137,8 @@ namespace HT.Cloud.Web
endpoints.MapControllerRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default", "{controller=Login}/{action=Index}/{id?}");
endpoints.MapControllerRoute("api", "api/{controller=ApiHome}/{action=Index}/{id?}");
});
endpoints.MapRazorPages();
});
}
}
}