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 <UniversityContext>(); DbInitialiser.Initialize(context); // context.Database.EnsureCreated(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } } host.Run(); // BuildWebHost(args).Run(); }
// 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, Ultimates_CricketContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); context.Database.Migrate(); DbInitialiser.Initialize(context); }
public void MockContext() { var options = new DbContextOptionsBuilder <CheckoutContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; context = new CheckoutContext(options); DbInitialiser.Initialize(context); }
//[Test] //public void UrlRewriteService_GetAll_ReturnsList() //{ // var data = UrlRewriteService.GetOptions(_context); // Assert.IsTrue(data.Count > 0); //} private ApplicationDbContext CreateContext() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "CrowdOrderDatabase").Options; // Insert seed data into the database using one instance of the context var context = new ApplicationDbContext(options); DbInitialiser.Initialize(context); return(context); }
public static IServiceProvider AddDb(this IServiceCollection services) { services.AddDbContext <CheckoutContext>(options => options.UseInMemoryDatabase("CheckoutDatabaseContext")); var serviceProvider = services.BuildServiceProvider(); var context = serviceProvider.GetService <CheckoutContext>(); DbInitialiser.Initialize(context); return(serviceProvider); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <CragLocationContext>(); DbInitialiser.Initialize(context); } host.Run(); }
private FantasyTraderDataContext GetContext(string methodName) { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <FantasyTraderDataContext>() .UseSqlite(connection) .Options; var context = new FantasyTraderDataContext(options); var dbInitialiser = new DbInitialiser(context, new NullLogger <DbInitialiser>()); dbInitialiser.Initialize(); return(context); }
private static void CreateDbIfNotExists(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var context = services.GetRequiredService <PhoneBookContext>(); DbInitialiser.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } }
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 <ContactFormContext>(); DbInitialiser.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while initialising the database."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { //var context = services.GetRequiredService<AnimalCrossingContext>(); DbInitialiser.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } FlyWithWing fly = new FlyWithWing(); FlyNoWay noFly = new FlyNoWay(); MallardDuck md = new MallardDuck(fly); RedHeadDuck red = new RedHeadDuck(fly); RubberDuck rd = new RubberDuck(noFly); md.Display(); md.Fly(); red.Display(); red.Fly(); rd.Display(); rd.Fly(); host.Run(); }
static async Task Main(string[] args) { await using var kbContext = new KingsbaneContext("Server=.\\SQLEXPRESS;Database=Kingsbane;Trusted_Connection=True;MultipleActiveResultSets=true"); await DbInitialiser.Initialize(kbContext); }