using Consul;
|
using FlexJobApi.Core;
|
using FlexJobApi.Core.Jobs;
|
using Furion;
|
using Furion.EventBus;
|
using Furion.Schedule;
|
using MediatR;
|
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Hosting;
|
using Newtonsoft.Json.Converters;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace FlexJobApi.Web.Entry
|
{
|
[AppStartup(2)]
|
public class Startup : AppStartup
|
{
|
public void ConfigureServices(IServiceCollection services)
|
{
|
services.AddHealthChecks();
|
|
services.AddConfigurableOptions<WxmpOptions>();
|
services.AddConfigurableOptions<AlipayOptions>();
|
services.AddConfigurableOptions<AliyunOptions>();
|
services.AddConfigurableOptions<BaiduOptions>();
|
|
services.AddComponent<LogServiceComponent>();
|
|
services.AddComponent<ConsulServiceComponent>();
|
|
services.AddComponent<EventBusServiceComponent>();
|
|
services.AddComponent<DistributedCacheServiceComponent>();
|
|
services.AddHttpRemote();
|
services.AddSingleton<AlipayUtils>();
|
services.AddSingleton<AliyunSmsUtils>();
|
services.AddSingleton<WxmpUtils>();
|
services.AddScoped<SmsUtils>();
|
|
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(App.Assemblies.ToArray()));
|
|
services.AddHostedService<XmlDocBuildHostedService>();
|
|
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
|
|
services.AddCorsAccessor();
|
|
services.AddHostedService<BuildDynamicControllersHostedService>();
|
|
services.AddSchedule(options =>
|
{
|
options.BuildSqlType = SqlTypes.SqlServer;
|
options.JobDetail.LogEnabled = true;
|
//options.AddPersistence<DbJobPersistence>();
|
options.AddJob<CalcTaskSatusByDateJob>(Triggers.Hourly());
|
options.AddJob<CalcUserAgeByIdCardJob>(Triggers.Daily());
|
options.AddJob<RefreshEnterpriseWalletStatusJob>(Triggers.PeriodMinutes(5));
|
options.AddJob<RefreshEnterpriseWalletTransactionStatusJob>(Triggers.PeriodMinutes(2));
|
options.AddJob<CompleteTaskSettlementT1Job>(Triggers.PeriodMinutes(2));
|
});
|
|
services.AddSpecificationDocuments(options =>
|
{
|
options.OperationFilter<CustomOperationIdFilter>();
|
options.SchemaFilter<EnumSchemaFilter>();
|
});
|
services.AddSwaggerGenNewtonsoftSupport();
|
|
services.AddMvcFilter<ResourceActionFilter>();
|
|
services.AddControllers()
|
.AddNewtonsoftJson(options =>
|
{
|
options.SerializerSettings.Converters.Add(new EmptyStringToNullConverter());
|
//options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
})
|
.AddFriendlyException()
|
.AddDataValidation()
|
.AddInjectWithUnifyResult<FriendlyResultProvider>();
|
|
}
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
|
{
|
// 解析事件总线发布服务
|
var eventPublisher = app.ApplicationServices.GetRequiredService<IEventPublisher>();
|
|
// 订阅
|
eventPublisher.OnExecuted += (sender, args) =>
|
{
|
Console.WriteLine($"事件 {args.Source.EventId} 执行状态:{args.Status},异常:{args.Exception},执行结果:{args.Result}");
|
};
|
|
if (env.IsDevelopment())
|
{
|
app.UseDeveloperExceptionPage();
|
}
|
|
app.UseUnifyResultStatusCodes();
|
|
//app.UseHttpsRedirection();
|
|
app.UseRouting();
|
|
app.UseCorsAccessor();
|
|
app.UseAuthentication();
|
app.UseAuthorization();
|
|
app.UseInject(string.Empty);
|
|
app.UseStaticFiles();
|
app.UseScheduleUI();
|
|
app.UseSpecificationDocuments();
|
|
app.UseEndpoints(endpoints =>
|
{
|
endpoints.MapControllers();
|
endpoints.MapHealthChecks("/healthz");
|
});
|
|
app.UseComponent<ConsulApplicationComponent>(env);
|
|
//lifetime.ApplicationStarted.Register(async () =>
|
//{
|
// await ResourceUtils.BuildDynamicControllersAsync();
|
//});
|
}
|
}
|
}
|