// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddDomainDependencies(); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "wwwroot"; }); services.AddSwaggerDocument(config => { config.PostProcess = document => { document.Info.Version = "1.0.0v"; document.Info.Title = "THD Simulation"; document.Info.Description = "ASP.NET Core web API"; }; }); ConfigureCors(services, Configuration); services.Configure <AuthTokenProviderOption>(Configuration.GetSection(typeof(AuthTokenProviderOption).Name)); services.Configure <List <Attribute> >(Configuration.GetSection("FixedAttributes")); var securityKey = Configuration.GetSection("AuthTokenProviderOption:JwtKey").Value; var connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddAuthOptions(securityKey); services.AddDbContext(connectionString); DBInitializerHelper.InizializationAsync(services).Wait(); ConfigureAutomapper(services); services.Configure <List <Attribute> >(Configuration.GetSection("FixedAttributes")); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <DataContext>(); DBInitializerHelper.CreateDefaultData(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while creating default database records."); } } host.Run(); }