106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using ZhonTai;
|
|
using ZhonTai.Admin.Core;
|
|
using ZhonTai.Admin.Core.Configs;
|
|
using ZhonTai.Admin.Core.Startup;
|
|
using ZhonTai.ApiUI;
|
|
using NPP.SmartSchedue.Api.Core.Consts;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyModel;
|
|
using Savorboard.CAP.InMemoryMessageQueue;
|
|
using System.Reflection;
|
|
using System.Linq;
|
|
using Autofac;
|
|
using DotNetCore.CAP;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NPP.SmartSchedue.Api.Core.Repositories;
|
|
using NPP.SmartSchedue.Api;
|
|
|
|
new HostApp(new HostAppOptions()
|
|
{
|
|
//配置FreeSql
|
|
ConfigureFreeSql = (freeSql, dbConfig) => { },
|
|
|
|
//配置前置服务
|
|
ConfigurePreServices = context =>
|
|
{
|
|
var dbConfig = AppInfo.GetOptions<DbConfig>();
|
|
if (dbConfig.Key.NotNull())
|
|
{
|
|
DbKeys.AppDb = dbConfig.Key;
|
|
}
|
|
},
|
|
//配置后置服务
|
|
ConfigurePostServices = context =>
|
|
{
|
|
//添加cap事件总线
|
|
var appConfig = AppInfo.GetOptions<AppConfig>();
|
|
Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
|
|
.Where(a => appConfig.AssemblyNames.Contains(a.Name))
|
|
.Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
|
|
|
|
var dbConfig = AppInfo.GetOptions<DbConfig>();
|
|
var rabbitMQ = context.Configuration.GetSection("CAP:RabbitMq").Get<RabbitMQOptions>();
|
|
context.Services.AddCap(config =>
|
|
{
|
|
config.UseInMemoryStorage();
|
|
config.UseInMemoryMessageQueue();
|
|
|
|
//<PackageReference Include="DotNetCore.CAP.MySql" Version="8.3.2" />
|
|
//<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.3.2" />
|
|
|
|
//config.UseMySql(dbConfig.ConnectionString);
|
|
//config.UseRabbitMQ(mqConfig => {
|
|
// mqConfig.HostName = rabbitMQ.HostName;
|
|
// mqConfig.Port = rabbitMQ.Port;
|
|
// mqConfig.UserName = rabbitMQ.UserName;
|
|
// mqConfig.Password = rabbitMQ.Password;
|
|
// mqConfig.ExchangeName = rabbitMQ.ExchangeName;
|
|
//});
|
|
config.UseDashboard();
|
|
}).AddSubscriberAssembly(assemblies);
|
|
|
|
// 注册设备相关Repository服务
|
|
context.Services.AddEquipmentRepositories();
|
|
|
|
// 注册算法引擎服务
|
|
context.Services.AddAlgorithmEngines();
|
|
},
|
|
//配置Autofac容器
|
|
ConfigureAutofacContainer = (builder, context) =>
|
|
{
|
|
builder.RegisterGeneric(typeof(AppRepositoryBase<>)).InstancePerLifetimeScope().PropertiesAutowired();
|
|
},
|
|
//配置Mvc
|
|
ConfigureMvcBuilder = (builder, context) => { },
|
|
//配置后置中间件
|
|
ConfigurePostMiddleware = context =>
|
|
{
|
|
var app = context.App;
|
|
var env = app.Environment;
|
|
var appConfig = AppInfo.GetOptions<AppConfig>();
|
|
|
|
#region 新版Api文档
|
|
|
|
if (env.IsDevelopment() || appConfig.ApiUI.Enable)
|
|
{
|
|
app.UseApiUI(options =>
|
|
{
|
|
options.RoutePrefix = appConfig.ApiUI.RoutePrefix;
|
|
var routePath = options.RoutePrefix.NotNull() ? $"{options.RoutePrefix}/" : "";
|
|
appConfig.Swagger.Projects?.ForEach(project =>
|
|
{
|
|
options.SwaggerEndpoint($"/{routePath}swagger/{project.Code.ToLower()}/swagger.json",
|
|
project.Name);
|
|
});
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}).Run(args);
|
|
|
|
public partial class Program
|
|
{
|
|
} |