Browse Source

Update sample app Program.cs

pull/211/head
gdlcf88 4 years ago
parent
commit
7f86174fcf
  1. 24
      samples/EShopSample/aspnet-core/src/EShopSample.Web/Program.cs
  2. 18
      samples/EShopSample/aspnet-core/src/EShopSample.Web/Startup.cs

24
samples/EShopSample/aspnet-core/src/EShopSample.Web/Program.cs

@ -1,5 +1,8 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
@ -8,7 +11,7 @@ namespace EShopSample.Web
{
public class Program
{
public static int Main(string[] args)
public static async Task<int> Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
#if DEBUG
@ -27,7 +30,15 @@ namespace EShopSample.Web
try
{
Log.Information("Starting web host.");
CreateHostBuilder(args).Build().Run();
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
.UseAutofac()
.UseSerilog();
await builder.AddApplicationAsync<EShopSampleWebModule>();
var app = builder.Build();
await app.InitializeApplicationAsync();
app.MapGet("ping", () => "pong");
await app.RunAsync();
return 0;
}
catch (Exception ex)
@ -40,14 +51,5 @@ namespace EShopSample.Web
Log.CloseAndFlush();
}
}
internal static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseAutofac()
.UseSerilog();
}
}

18
samples/EShopSample/aspnet-core/src/EShopSample.Web/Startup.cs

@ -1,18 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace EShopSample.Web
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<EShopSampleWebModule>();
}
public void Configure(IApplicationBuilder app)
{
app.InitializeApplication();
}
}
}
Loading…
Cancel
Save