diff --git a/apps/auth-server/src/EShopOnAbp.AuthServer/Program.cs b/apps/auth-server/src/EShopOnAbp.AuthServer/Program.cs index efe95993..94508848 100644 --- a/apps/auth-server/src/EShopOnAbp.AuthServer/Program.cs +++ b/apps/auth-server/src/EShopOnAbp.AuthServer/Program.cs @@ -2,8 +2,6 @@ using System; using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Serilog; namespace EShopOnAbp.AuthServer; @@ -19,14 +17,7 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - var builder = WebApplication.CreateBuilder(args); - builder.Host - .AddAppSettingsSecretsJson() - .UseAutofac() - .UseSerilog(); - - await builder.AddApplicationAsync(); - var app = builder.Build(); + var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); await app.InitializeApplicationAsync(); await app.RunAsync(); diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Program.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Program.cs index 305cbc91..02db8160 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Program.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Program.cs @@ -2,8 +2,6 @@ using System; using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Serilog; namespace EShopOnAbp.PublicWeb; @@ -19,17 +17,10 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - var builder = WebApplication.CreateBuilder(args); - builder.Host - .AddAppSettingsSecretsJson() - .UseAutofac() - .UseSerilog(); - - await builder.AddApplicationAsync(); - var app = builder.Build(); + var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); await app.InitializeApplicationAsync(); await app.RunAsync(); - + return 0; } catch (Exception ex) diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs new file mode 100644 index 00000000..90faea26 --- /dev/null +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using Volo.Abp.Modularity; + +namespace EShopOnAbp.Shared.Hosting.AspNetCore; + +public static class ApplicationBuilderHelper +{ + public static async Task BuildApplicationAsync(string[] args) + where TStartupModule : IAbpModule + { + var builder = WebApplication.CreateBuilder(args); + builder.Host + .AddAppSettingsSecretsJson() + .UseAutofac() + .UseSerilog(); + + await builder.AddApplicationAsync(); + return builder.Build(); + } +} \ No newline at end of file