sunpengfei
2025-08-06 c914975bffe90f808a05dba2c53d4a750e8403c0
FlexJobApi.Core/FlexJobApiCoreStartup.cs
@@ -1,4 +1,5 @@
using Furion;
using Consul;
using Furion;
using Furion.EventBus;
using MediatR;
using Microsoft.AspNetCore.Builder;
@@ -19,6 +20,8 @@
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHealthChecks();
            services.AddConsoleFormatter(options =>
            {
                options.WithTraceId = true;
@@ -41,6 +44,12 @@
                options.WithStackFrame = true;
            });
            services.AddConfigurableOptions<AliyunOptions>();
            services.AddHttpRemote();
            services.AddComponent<ConsulServiceComponent>();
            services.AddComponent<EventBusServiceComponent>();
            services.AddComponent<DistributedCacheServiceComponent>();
@@ -48,22 +57,29 @@
            services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(App.Assemblies.ToArray()));
            services.AddHostedService<XmlDocBuildHostedService>();
            services.AddHostedService<BuildDynamicControllersHostedService>();
            services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
            services.AddCorsAccessor();
            services.AddSpecificationDocuments(options =>
            {
                options.OperationFilter<CustomOperationIdFilter>();
                options.SchemaFilter<EnumSchemaFilter>();
            });
            services.AddControllers()
                    .AddNewtonsoftJson(options =>
                    {
                        options.SerializerSettings.Converters.Add(new StringEnumConverter());
                        //options.SerializerSettings.Converters.Add(new StringEnumConverter());
                    })
                    .AddFriendlyException()
                    .AddDataValidation()
                    .AddInjectWithUnifyResult<FriendlyResultProvider>();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
        {
            // 解析事件总线发布服务
            var eventPublisher = app.ApplicationServices.GetRequiredService<IEventPublisher>();
@@ -81,7 +97,7 @@
            app.UseUnifyResultStatusCodes();
            app.UseHttpsRedirection();
            //app.UseHttpsRedirection();
            app.UseRouting();
@@ -92,10 +108,20 @@
            app.UseInject(string.Empty);
            app.UseSpecificationDocuments();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/healthz");
            });
            app.UseComponent<ConsulApplicationComponent>(env);
            //lifetime.ApplicationStarted.Register(async () =>
            //{
            //    await ResourceUtils.BuildDynamicControllersAsync();
            //});
        }
    }
}