Example #1
0
 /// <summary>
 /// 注册上下文初始化器
 /// </summary>
 /// <param name="contextType">上下文类型</param>
 /// <param name="initializer">上下文初始化器</param>
 public void RegisterInitializer(Type contextType, DbContextInitializerBase initializer)
 {
     if (_contextInitializerDict.ContainsKey(contextType))
     {
         return;
     }
     _contextInitializerDict[contextType] = initializer;
     initializer.Initialize();
 }
Example #2
0
        /// <summary>
        /// 获取默认业务上下文配置信息
        /// </summary>
        /// <returns></returns>
        //protected virtual DbContextConfig GetDefaultDbContextConfig()
        //{
        //    return new DbContextConfig()
        //    {
        //        ConnectionStringName = "default",
        //        ContextType = typeof(DefaultDbContext),
        //        InitializerConfig = new DbContextInitializerConfig()
        //        {
        //            InitializerType = typeof(DefaultDbContextInitializer),
        //            EntityMapperAssemblies = MapperAssemblyFinder.FindAll()
        //        }
        //    };
        //}

        /// <summary>
        /// 获取默认日志上下文配置信息
        /// </summary>
        /// <returns></returns>
        //protected virtual DbContextConfig GetLoggingDbContextConfig()
        //{
        //    return new DbContextConfig()
        //    {
        //        ConnectionStringName = "default",
        //        ContextType = typeof(LoggingDbContext),
        //        InitializerConfig = new DbContextInitializerConfig()
        //        {
        //            InitializerType = typeof(LoggingDbContextInitializer),
        //            EntityMapperAssemblies = { typeof(LoggingDbContext).Assembly }
        //        }
        //    };
        //}

        /// <summary>
        /// 初始化数据上下文
        /// </summary>
        /// <param name="config">数据上下文配置信息</param>
        private static void DbContextInit()
        {
            DbContextInitializerBase initializer = CreateInitializer();

            DbContextManager.Instance.RegisterInitializer(typeof(DefaultDbContext), initializer);
        }