public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); // Get service collection from the host object using (var scope = host.Services.CreateScope()) { // Get all the services registered in the dependency injection container var services = scope.ServiceProvider; try { // Register the catalog context var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } host.Run(); }
//Notes:IIS - Internet Information service - a piece of software in windows that hosts web application.Similar to Tomcat in Linux public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); //Here we are creating a large object so we need to let garbage colelctor know we dont need this anymore. //Here when we reach the end of using statement we dont want scope anymore as scope can be alarge object using (var scope = host.Services.CreateScope())//Wait until my Database is creted before seeding { var services = scope.ServiceProvider; var context = services.GetRequiredService <CatalogContext>();//tell me if DB's created by CatalogContext is there CatalogSeed.SeedAsync(context).Wait(); } host.Run(); }
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 <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "ERROR SEEDING"); } } host.Run(); }
public static void Main(string[] args) { //this is my docker var host = BuildWebHost(args); //creating the scope, give me a docker image. wrapping in a user statement //so when the system is killed it kills the docker image //will call dispose when reaches end of the line using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) // setting up docker destroy docer andclean memory if use in a using loop. { var services = scope.ServiceProvider; //docker providing alll the provider one iscatalogcontext var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger>(); logger.LogError("Failed to get Database context", ex); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } using (var scope = app.ApplicationServices.CreateScope()) { var ctx = scope.ServiceProvider.GetService <CatalogContext> (); CatalogSeed.SeedAsync(ctx).Wait(); } app.UseSwagger() .UseSwaggerUI( c => c.SwaggerEndpoint($"/swagger/v1/swagger.json", "ProductCatalogAPI V1") ); //app.UseHttpsRedirection (); app.UseMvc(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception e) { var logger = services.GetRequiredService <ILogger>(); logger.Log(LogLevel.Error, $"Exception {e.Message}: InnerException: {e.InnerException?.Message}", e.StackTrace); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { //get the services collection var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database"); } } host.Run(); }
public static void Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); MigrateDatabase.EnsureCreated(context); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { //Host'u alarak service collectiona eriştik. Daha sonra buradan register olmuş olan DbContextimizi alıp seeddata methoduna gönderdik. var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database"); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); //From the scope, I will get the services using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { //Obtained an instance of catalog context var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error Occured while seeding values"); } } host.Run(); }
public static void Main(string[] args) { var hostBuilder = CreateHostBuilder(args); var host = hostBuilder.Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "Seeding error"); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); context.Database.Migrate(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { Console.WriteLine(ex.Message); //var logger = services.GetRequiredService<ILogger>(); //logger.LogError(ex, "An error occured while seeding database"); } } host.Run(); }
public static void Main(string[] args) { //adding of the dummy data in catalog seed //host is docker image var host = BuildWebHost(args); //give me a scope/instance of the docket image using (var scope = host.Services.CreateScope()) { //get all the list of services on docker image var services = scope.ServiceProvider; //locate the catalog context out of the list of services var context = services.GetRequiredService <CatalogContext>(); //add dummy data in catalog context, by calling Seed funtion //call the wait on this async function becuse main cannot be made to async funtion CatalogSeed.SeedAsync(context).Wait(); } //run docker image host.Run(); }
public static void Main(string[] args) { // TODO: Refactor to evironment // CreateWebHostBuilder(args).Build().Run(); ---> Default var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CatalogContext>(); CatalogSeed.SeedAsync(context).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error Occured while seeding the database"); } } host.Run(); }