/// <summary> /// Build services factory. /// </summary> /// <param name="host">Application Host.</param> public static void Build(IHost host) { host = host ?? throw new ArgumentNullException(nameof(host)); using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; RuntimeMigrations.Initialize(services); ApplicationContextSeed.Initialize(services); }
private static IWebHost CreateDatabaseIfNotExists(this IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationContext>(); ApplicationContextSeed.Initialize(context); } catch (Exception ex) { Console.WriteLine(ex); } } return(host); }