加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 3.69 KB
一键复制 编辑 原始数据 按行查看 历史
zhangxinya 提交于 2020-06-17 16:46 . first add
// -----------------------------------------------------------------------
// <copyright file="Program.cs" company="Kengic">
// Copyright (c) Kengic. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.IO;
using System.Threading.Tasks;
using IdentityServer4.EntityFramework.DbContexts;
using Kengic.Identity.API.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Serilog;
namespace Kengic.Identity.API
{
/// <summary> A program. </summary>
public static class Program
{
/// <summary> The namespace. </summary>
public static readonly string Namespace = typeof(Program).Namespace;
/// <summary> Name of the application. </summary>
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
/// <summary> Main entry-point for this application. </summary>
/// <param name="args"> The arguments. </param>
/// <returns> Exit-code for the process - 0 for success, else an error code. </returns>
public static Task Main(string[] args)
{
var configuration = GetConfiguration();
return CreateHostBuilder(configuration, args)
.Build()
.MigrateDbContext<ConfigurationDbContext>((context, services) => new ConfigurationDbContextSeed()
.SeedAsync(context, configuration)
.Wait())
.MigrateDbContext<PersistedGrantDbContext>((_, __) => { })
.MigrateDbContext<ApplicationDbContext>((context, services) =>
{
var env = services.GetService<IWebHostEnvironment>();
var logger = services.GetService<ILogger<ApplicationDbContextSeed>>();
var settings = services.GetService<IOptions<AppSettings>>();
new ApplicationDbContextSeed(services)
.SeedAsync(context, env, logger, settings, 0)
.Wait();
}).RunAsync();
}
/// <summary>
/// Creates web host builder.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="args">The arguments.</param>
/// <returns>The new web host builder.</returns>
private static IHostBuilder CreateHostBuilder(IConfiguration configuration, string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder
.CaptureStartupErrors(false)
.UseStartup<Startup>()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseConfiguration(configuration)
.UseSerilog((ctx, config) => config
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Debug()
.WriteTo.Console()));
/// <summary> Gets the configuration. </summary>
/// <returns> The configuration. </returns>
private static IConfiguration GetConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
return builder.Build();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化