コード例 #1
0
ファイル: Startup.cs プロジェクト: RichardT-B/MoviesAPI
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug( );

            app.UseMvc( );

            MoviesInitializer.Initialize(app.ApplicationServices);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: StanislavTsanev/movies
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var dbContext = scope.ServiceProvider.GetService <MoviesContext>();
                    dbContext.Database.EnsureCreated();
                    MoviesInitializer.Initialize(dbContext);
                }
                catch (Exception e)
                {
                    var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "An error occured while initializing the database.");
                }
            }

            host.Run();
        }