コード例 #1
0
        public static Context CreateTest(DbContextOptions options, IContextConfig config)
        {
            var context = new Context(options, config);

            context.Database.EnsureCreated();
            return(context);
        }
コード例 #2
0
        public static Context Create(IContextConfig contextConfig)
        {
            var context = new Context(contextConfig);

            // context.Database.EnsureCreated();
            return(context);
        }
コード例 #3
0
 public Context(IContextConfig config)
 {
     this.config = config;
     if (config.Application == ApplicationType.Mobile || config.Application == ApplicationType.Web)
     {
         Database.Migrate();
     }
 }
コード例 #4
0
 public Context(DbContextOptions options, IContextConfig config) : base(options)
 {
     this.config = config;
     if (config.Application == ApplicationType.Test)
     {
         Database.Migrate();
     }
 }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
ファイル: EntitiesContext.cs プロジェクト: DofD/UnitOfWork
        /// <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);
        }
コード例 #7
0
        // 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());
        }
コード例 #8
0
 public static ContextFacade Create(IContextConfig contextConfig) => new ContextFacade(contextConfig);