/// <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);
        }
示例#2
0
        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);
        }