You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
6.4 KiB
138 lines
6.4 KiB
using Kean.Infrastructure.Hangfire;
|
|
using Kean.Infrastructure.Orleans;
|
|
using Kean.Infrastructure.SignalR;
|
|
using Kean.Infrastructure.Soap;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
|
|
namespace Kean.Presentation.Rest
|
|
{
|
|
/// <summary>
|
|
/// 应用程序启动类
|
|
/// </summary>
|
|
public class Startup
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
/// <summary>
|
|
/// 初始化 Kean.Presentation.Rest.Startup 类的新实例
|
|
/// </summary>
|
|
public Startup(IConfiguration configuration) =>
|
|
_configuration = configuration;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
private static IServiceCollection DependencyInject(IServiceCollection services) => services
|
|
.Add<Infrastructure.Configuration.DependencyInjection>()
|
|
.Add<Infrastructure.Database.Repository.DependencyInjection>()
|
|
.Add<Infrastructure.NoSql.Repository.DependencyInjection>()
|
|
.Add<Infrastructure.Repository.DependencyInjection>()
|
|
.Add<Infrastructure.Soap.References.DependencyInjection>()
|
|
.Add<Domain.Seedwork.DependencyInjection>()
|
|
.Add<Domain.App.DependencyInjection>()
|
|
.Add<Domain.Basic.DependencyInjection>()
|
|
.Add<Domain.Identity.DependencyInjection>()
|
|
.Add<Domain.Message.DependencyInjection>()
|
|
.Add<Domain.Material.DependencyInjection>()
|
|
.Add<Domain.Order.DependencyInjection>()
|
|
.Add<Domain.Stock.DependencyInjection>()
|
|
.Add<Domain.Task.DependencyInjection>()
|
|
.Add<Domain.Wcs.DependencyInjection>()
|
|
.Add<Application.Command.DependencyInjection>()
|
|
.Add<Application.Query.DependencyInjection>()
|
|
.Add<Application.Utilities.DependencyInjection>();
|
|
|
|
/// <summary>
|
|
/// 将服务添加到托盘
|
|
/// </summary>
|
|
public void ConfigureServices(IServiceCollection services) =>
|
|
DependencyInject(services
|
|
.AddSwaggerGen(options =>
|
|
{
|
|
options.OperationFilter<SwaggerFilter>();
|
|
options.CustomSchemaIds(_ => Guid.NewGuid().ToString("N"));
|
|
options.OrderActionsBy(a => a.RelativePath);
|
|
//options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "Swagger.xml"), true);
|
|
options.SwaggerDoc(_configuration["Swagger:Version"], new()
|
|
{
|
|
Title = _configuration["Swagger:Title"],
|
|
Version = _configuration["Swagger:Version"],
|
|
Contact = new()
|
|
{
|
|
Name = _configuration["Swagger:Contact:Name"],
|
|
Email = _configuration["Swagger:Contact:Email"]
|
|
}
|
|
});
|
|
})
|
|
.AddOrleans(options =>
|
|
{
|
|
options.SiloPort = int.Parse(_configuration["Orleans:SiloPort"]);
|
|
options.GatewayPort = int.Parse(_configuration["Orleans:GatewayPort"]);
|
|
options.ClusterId = _configuration["Orleans:ClusterId"];
|
|
options.ServiceId = _configuration["Orleans:ServiceId"];
|
|
options.RedisClustering.ConnectionString = _configuration["Orleans:RedisClustering:ConnectionString"];
|
|
options.RedisClustering.Database = int.Parse(_configuration["Orleans:RedisClustering:Database"]);
|
|
options.ConfigureServices(services => DependencyInject(services));
|
|
})
|
|
.AddHangfire(options =>
|
|
{
|
|
options.RedisStorage.ConnectionString = _configuration["Hangfire:RedisStorage:ConnectionString"];
|
|
options.RedisStorage.Database = int.Parse(_configuration["Hangfire:RedisStorage:Database"]);
|
|
options.RecurringJobs.Add<Jobs.WcsInputJob>(_configuration["Hangfire:RecurringJobs:WcsInputJob"]);
|
|
options.RecurringJobs.Add<Jobs.WcsOutputJob>(_configuration["Hangfire:RecurringJobs:WcsOutputJob"]);
|
|
options.RecurringJobs.Add<Jobs.WcsStationJob>(_configuration["Hangfire:RecurringJobs:WcsStationJob"]);
|
|
//options.RecurringJobs.Add<Jobs.TVStatisticsJob>(_configuration["Hangfire:RecurringJobs:TVStatisticsJob"]);
|
|
options.RecurringJobs.Add<Jobs.ClearRecordJob>(_configuration["Hangfire:RecurringJobs:ClearRecordJob"]);
|
|
options.RecurringJobs.Add<Jobs.AutoPalletOutJob>(_configuration["Hangfire:RecurringJobs:AutoPalletOutJob"]);
|
|
})
|
|
.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(policy =>
|
|
{
|
|
policy.WithOrigins(_configuration["AllowedOrigins"].Split(';'))
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
})
|
|
.AddSignalR(options =>
|
|
{
|
|
options.Hubs.Add<Domain.Identity.Sockets.IOnlineSocket, Hubs.IdentityHub>();
|
|
options.Hubs.Add<Domain.Message.Sockets.IOnlineSocket, Hubs.MessageHub>();
|
|
//options.Hubs.Add<Kean.Application.Query.Sockets.IOnlineSocket, Hubs.StatisticsHub>();
|
|
})
|
|
.AddSoap(options =>
|
|
{
|
|
//options.Services.Add<Soaps.Services.MyService>();
|
|
//options.Services.Add<Soaps.Services.AgvApplyService>();
|
|
})
|
|
.AddControllers(options =>
|
|
{
|
|
options.Filters.Add<ActionFilter>();
|
|
options.Filters.Add<ExceptionFilter>();
|
|
})
|
|
.Services)
|
|
.Startup();
|
|
|
|
/// <summary>
|
|
/// 配置 HTTP 请求管道
|
|
/// </summary>
|
|
public void Configure(IApplicationBuilder app) => app
|
|
.UseOrleans()
|
|
.UseHangfire()
|
|
.UseSwagger()
|
|
.UseRouting()
|
|
.UseCors()
|
|
.UseBlacklist()
|
|
.UseAuthentication()
|
|
.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
endpoints.MapHubs();
|
|
//endpoints.MapSoaps();
|
|
});
|
|
}
|
|
}
|