Example #1
0
        public TemplateDbContext CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <TemplateDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            TemplateDbContextConfigurer.Configure(builder, configuration.GetConnectionString(TemplateConsts.ConnectionStringName));

            return(new TemplateDbContext(builder.Options));
        }
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext <TemplateDbContext>(options =>
         {
             if (options.ExistingConnection != null)
             {
                 TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
             }
             else
             {
                 TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
             }
             options.DbContextOptions.UseLoggerFactory(new LoggerFactory(new[]
             {
                 new ConsoleLoggerProvider((category, level)
                                           => category == DbLoggerCategory.Database.Command.Name &&
                                           level == LogLevel.Information, true)
             }));
         });
     }
 }