コード例 #1
0
        public QksDbContext CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <QksDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            QksDbContextConfigurer.Configure(builder, configuration.GetConnectionString(QksConsts.ConnectionStringName));

            return(new QksDbContext(builder.Options));
        }
コード例 #2
0
        public override void PreInitialize()
        {
            //Configuration.ReplaceService(typeof(IConnectionStringResolver), () =>
            //{
            //    IocManager.IocContainer.Register(
            //        Component.For<IConnectionStringResolver>()
            //            .ImplementedBy<MyConnectionStringResolver>()
            //            .LifestyleTransient()
            //        );
            //});
            Configuration.ReplaceService(typeof(IConnectionStringResolver), () =>
            {
                IocManager.IocContainer.Register(
                    Component.For <IConnectionStringResolver, IDbPerTenantConnectionStringResolver>()
                    .ImplementedBy <MyDbPerTenantConnectionStringResolver>()
                    .LifestyleTransient()
                    );
            });

            if (!SkipDbContextRegistration)
            {
                Configuration.Modules.AbpEfCore().AddDbContext <QksDbContext>(options =>
                {
                    if (options.ExistingConnection != null)
                    {
                        QksDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                    }
                    else
                    {
                        QksDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                    }
                });

                //if (_pluginOpt.Loaded) PluginEFCoreInit();
            }
        }