private static void ConfigureServices(IServiceCollection services) { string PathToDb = SimDbContext.FindDbFolder(Configuration.GetSection("Database").GetValue <string>("DbPath")) + System.IO.Path.DirectorySeparatorChar + "CoreSimFun.db"; Console.WriteLine("PathToDb: " + PathToDb); services.AddDbContext <SimDbContext>(options => options.UseSqlite("Data Source=" + PathToDb)); }
// 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(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Database var DB = new SimDbContext(app.ApplicationServices.GetRequiredService <DbContextOptions <SimDbContext> >()); DB.EnsureCreated(app.ApplicationServices); DB.DbInitialize(app.ApplicationServices); }
private static void Configure() { // Database var context = new SimDbContext(serviceProvider.GetRequiredService <DbContextOptions <SimDbContext> >()); context.EnsureCreated(serviceProvider); context.DbInitialize(serviceProvider); DB = new DbMgr(new UnitOfWork(context), new SimInfoRepository(context), new SimEventRepository(context)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); //Add DB services string PathToDb = SimDbContext.FindDbFolder(Configuration.GetSection("Database").GetValue <string>("DbPath")) + System.IO.Path.DirectorySeparatorChar + "CoreSimFun.db"; services.AddDbContext <SimDbContext>(options => options.UseSqlite("Data Source=" + PathToDb)); services.AddScoped <IUnitOfWork, UnitOfWork>(); services.AddScoped <IDbMgr, DbMgr>(); // Repositories services.AddScoped <ISimInfoRepository, SimInfoRepository>(); services.AddScoped <ISimEventRepository, SimEventRepository>(); }
public UnitOfWork(SimDbContext context) { Context = context; }
public UnitOfWork() { Context = new SimDbContext(); }