117 lines
3.7 KiB
C#
117 lines
3.7 KiB
C#
using IGeekFan.AspNetCore.Knife4jUI;
|
||
using JNPF.Common.Cache;
|
||
using JNPF.Common.Core.Handlers;
|
||
using JNPF.Common.Security;
|
||
using JNPF.DependencyInjection;
|
||
using JNPF.SpecificationDocument;
|
||
using JNPF.TaskScheduler.Interfaces.TaskScheduler;
|
||
using JNPF.VisualDev;
|
||
using Microsoft.Extensions.Options;
|
||
using Senparc.CO2NET;
|
||
using Senparc.CO2NET.RegisterServices;
|
||
using Senparc.Weixin;
|
||
using Senparc.Weixin.Entities;
|
||
using Senparc.Weixin.RegisterServices;
|
||
using Tnb.Common.Redis;
|
||
using Tnb.ProductionMgr;
|
||
using Tnb.WarehouseMgr;
|
||
|
||
namespace JNPF.API.Entry;
|
||
|
||
public class Startup : AppStartup
|
||
{
|
||
public void ConfigureServices(IServiceCollection services)
|
||
{
|
||
// 注册和配置Mvc和api服务
|
||
services.ConfigureMvcController();
|
||
|
||
// 注册和配置SqlSugar
|
||
services.ConfigureSqlSugar();
|
||
|
||
// 注册EventBus服务
|
||
services.ConfigureEventBus();
|
||
|
||
// 注册和配置日志服务
|
||
services.ConfigureLogging();
|
||
|
||
// 注册和配置存储服务
|
||
services.ConfigureOSSService();
|
||
|
||
// 任务调度
|
||
//services.AddSchedule(options =>
|
||
//{
|
||
// options.AddPersistence<DbJobPersistence>();
|
||
//});
|
||
|
||
// 任务调度
|
||
services.AddTaskScheduler();
|
||
|
||
services.AddMemoryCache(); // 使用本地缓存必须添加
|
||
services.AddConfigurableOptions<CacheOptions>();
|
||
services.AddSingleton( typeof(ISingleton), typeof(RedisData));
|
||
// 微信
|
||
services.AddSenparcGlobalServices(App.Configuration) // Senparc.CO2NET 全局注册
|
||
.AddSenparcWeixinServices(App.Configuration); // Senparc.Weixin 注册(如果使用Senparc.Weixin SDK则添加)
|
||
|
||
services.AddOverideVisualDev();
|
||
|
||
//定时任务
|
||
services.AddHostedService<TimedTaskBackgroundService>();
|
||
//services.AddHostedService<RedisBackGround>();
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
|
||
{
|
||
// 添加状态码拦截中间件
|
||
app.UseUnifyResultStatusCodes();
|
||
|
||
// app.UseHttpsRedirection(); // 强制https
|
||
app.UseStaticFiles();
|
||
|
||
#region 微信
|
||
IRegisterService register = RegisterService.Start(senparcSetting.Value).UseSenparcGlobal();//启动 CO2NET 全局注册,必须!
|
||
register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注册,必须!
|
||
#endregion
|
||
|
||
app.UseWebSockets();
|
||
|
||
app.UseRouting();
|
||
|
||
app.UseCorsAccessor();
|
||
|
||
app.UseAuthentication();
|
||
app.UseAuthorization();
|
||
|
||
// 任务调度看板
|
||
app.UseScheduleUI();
|
||
|
||
app.UseKnife4UI(options =>
|
||
{
|
||
options.RoutePrefix = "newapi"; // 配置 Knife4UI 路由地址,现在是 /newapi
|
||
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
||
{
|
||
options.SwaggerEndpoint("/" + groupInfo.RouteTemplate, groupInfo.Title);
|
||
}
|
||
});
|
||
|
||
app.UseInject(string.Empty);
|
||
|
||
//app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService<IMHandler>());
|
||
app.MapWebSocketManager("/websocket", serviceProvider.GetRequiredService<IMHandler>());
|
||
|
||
app.UseEndpoints(endpoints =>
|
||
{
|
||
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
|
||
});
|
||
|
||
SnowflakeIdHelper.InitYitIdWorker();
|
||
|
||
bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob");
|
||
if (isStartTimeJob)
|
||
serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
|
||
}
|
||
} |