sunpengfei
2025-08-08 32288af3e5f12bc48d8360114c872fde5d9ff4a8
FlexJobApi.Core/FlexJobApiCoreStartup.cs
@@ -1,4 +1,5 @@
using Furion;
using Consul;
using Furion;
using Furion.EventBus;
using MediatR;
using Microsoft.AspNetCore.Builder;
@@ -19,27 +20,32 @@
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHealthChecks();
            services.AddConsoleFormatter(options =>
            {
                options.WithTraceId = true;
                options.WithStackFrame = true;
            });
            services.AddFileLogging(options =>
            {
                options.WithTraceId = true;
                options.WithStackFrame = true;
                options.FileNameRule = fileName =>
                {
                    return string.Format(fileName, DateTime.UtcNow);    // 如果是本地时间使用 DateTime.Now
                    return string.Format(fileName, DateTime.Now);
                };
            });
            services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
            {
                options.WithTraceId = true;
                options.WithStackFrame = true;
            });
            //services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
            //{
            //    options.WithTraceId = true;
            //});
            services.AddConfigurableOptions<AliyunOptions>();
            services.AddHttpRemote();
            services.AddComponent<ConsulServiceComponent>();
            services.AddComponent<EventBusServiceComponent>();
@@ -53,22 +59,27 @@
            services.AddCorsAccessor();
            services.AddHostedService<BuildDynamicControllersHostedService>();
            services.AddSpecificationDocuments(options =>
            {
                options.OperationFilter<FurionCustomOperationIdFilter>();
                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>();
            services.AddMvcFilter<ResourceActionFilter>();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
        {
            // 解析事件总线发布服务
            var eventPublisher = app.ApplicationServices.GetRequiredService<IEventPublisher>();
@@ -86,7 +97,7 @@
            app.UseUnifyResultStatusCodes();
            app.UseHttpsRedirection();
            //app.UseHttpsRedirection();
            app.UseRouting();
@@ -102,7 +113,15 @@
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/healthz");
            });
            app.UseComponent<ConsulApplicationComponent>(env);
            //lifetime.ApplicationStarted.Register(async () =>
            //{
            //    await ResourceUtils.BuildDynamicControllersAsync();
            //});
        }
    }
}