public static Context CreateTest(DbContextOptions options, IContextConfig config) { var context = new Context(options, config); context.Database.EnsureCreated(); return(context); }
public static Context Create(IContextConfig contextConfig) { var context = new Context(contextConfig); // context.Database.EnsureCreated(); return(context); }
public Context(IContextConfig config) { this.config = config; if (config.Application == ApplicationType.Mobile || config.Application == ApplicationType.Web) { Database.Migrate(); } }
public Context(DbContextOptions options, IContextConfig config) : base(options) { this.config = config; if (config.Application == ApplicationType.Test) { Database.Migrate(); } }
public ContextFacade(IContextConfig contextConfig) { if (contextConfig.Application == ApplicationType.Test) { if (_connection == null) { _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); var optionsBuilder = new DbContextOptionsBuilder <Context>() .UseSqlite(_connection, options => options.MigrationsAssembly("BudgetUnderControl.Migrations.SQLite")).Options; _context = Context.CreateTest(optionsBuilder, contextConfig); } } else { _context = Context.Create(contextConfig); } }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="EntitiesContext" /> /// </summary> /// <param name="databaseInitializer">Инициализатор</param> /// <param name="contextConfig">Настройки контекста</param> /// <param name="logger">Логировщик</param> protected internal EntitiesContext( IDatabaseInitializer<EntitiesContext> databaseInitializer, IContextConfig contextConfig, ILogger logger) : base(contextConfig.ConnectionString) { this._contextConfig = contextConfig; this._logger = logger; this.Configuration.LazyLoadingEnabled = false; this.Configuration.ProxyCreationEnabled = false; if (this._contextConfig.LogSQL) { this.Database.Log = s => this._logger.Trace(s); } Database.SetInitializer(databaseInitializer); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IContextConfig contextConfig)//, ITestDataSeeder testDataSeeder) { if (contextConfig.Application == ApplicationType.Test) { //testDataSeeder.SeedAsync().Wait(); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //app.UseHttpsRedirection(); app.UseRouting(); app.UseCustomExceptionHandler(); app.UseAuthentication(); app.UseCors(options => options .AllowAnyMethod() .AllowAnyHeader() .SetIsOriginAllowed(origin => true) .AllowCredentials() ); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(x => x.MapControllers()); }
public static ContextFacade Create(IContextConfig contextConfig) => new ContextFacade(contextConfig);