public virtual void addDatabaseContext(IServiceCollection services) { // for the model/migration stuff mostly services.AddDbContext <WorkerProfileApiContext> (options => options.UseSqlServer(Configuration.GetSection("DatabaseConnection").Value.ToString(), x => x.UseNetTopologySuite())); var ctxFactory = new MyDbContextFactory(Configuration.GetSection("DatabaseConnection").Value.ToString()); using (var cnt = ctxFactory.Get()) { cnt.Database.Migrate(); } services.AddSingleton <MyDbContextFactory> (g => ctxFactory); services.AddSingleton <GeometryFactory> (g => NtsGeometryServices.Instance.CreateGeometryFactory(4326)); }
public DefaultSkillsRepository(MyDbContextFactory contextFactory) { _ctxFactory = contextFactory; }
public BaseService() { dbContext = MyDbContextFactory.GetMyDbContext(); }
void Application_EndRequest(object sender, EventArgs e) { //EndRequest是在响应Request时最后一个触发的事件 //但在对象被释放或者从新建立以前,适合在这个时候清理代码 MyDbContextFactory.DisposeMyDbContext(); }
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, MyDbContextFactory ctxFactory) { base.Configure(app, env, ctxFactory); }
public DefaultProfilesRepository(MyDbContextFactory contextFactory, IGeometryMapper geometryMapper) { _ctxFactory = contextFactory; _geometryMapper = geometryMapper; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env, MyDbContextFactory ctxFactory) { app.UseOpenApi(); app.UseSwaggerUi3(); app.UseMiddleware <ApiExceptionsHandlingMiddleware> (); app.UseHsts(); app.UseCors(MyCorsPolicy); app.UseHttpsRedirection(); app.UseRouting(); enableAuthentication(app); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }