public void Load()
        {
            var repositoryType = typeof(IRepository <>).FullName;
            var baseType       = typeof(IRepository);

            foreach (var assembly in assemblies)
            {
                var types = assembly.GetTypes().Where(o => o.IsClass && !o.IsAbstract && !o.IsGenericTypeDefinition && o.GetInterface(repositoryType) != null);
                foreach (var type in types)
                {
                    //验证方法virtual
                    EntityUtil.CheckVirtualType(type);

                    var entityType = ReflectionHelper.GetEntityTypeFromRepositoryType(type);
                    var metadata   = RepositoryFramework.GetDefineMetadataAndCheck(entityType);

                    //使用继承的方式创建代理
                    var proxy      = ProxyProvider.Generator.CreateClassProxy(type, new RepositoryInterceptor());
                    var interfaces = type.GetInterfaces().Where(o => o != baseType);
                    foreach (var i in interfaces)
                    {
                        this.register.Register(i, proxy);
                        //ServiceLocator.Current.Register(i, proxy);
                        //Container.Register(i, proxy);
                    }
                }
            }
        }
Esempio n. 2
0
        public MongoCollection <TEntity> GetCollection <TEntity>(ShardParams shardParams)
        {
            var strategy = RepositoryFramework.GetShardStrategy(typeof(TEntity));

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy", String.Format("无法找到类型 {0} 对应的分区策略信息。", typeof(TEntity).FullName));
            }

            var shardId     = strategy.GetShardId(shardParams);
            var partitionId = strategy.GetPartitionId(shardParams);

            var database = GetDatabase(shardId);

            if (partitionId == null)
            {
                var metadata = RepositoryFramework.GetDefineMetadata(typeof(TEntity));
                if (metadata != null && !String.IsNullOrEmpty(metadata.Table))
                {
                    return(database.GetCollection <TEntity>(metadata.Table));
                }

                return(database.GetCollection <TEntity>(typeof(TEntity).Name));
            }
            return(database.GetCollection <TEntity>(partitionId.RealTableName));
        }
Esempio n. 3
0
 public AbstractRepository()
 {
     sessionFactory = RepositoryFramework.GetSessionFactory(typeof(TEntity));
     if (sessionFactory == null)
     {
         throw new ArgumentNullException("sessionFactory", String.Format("类型 {0} 未配置 IShardSessionFactory", typeof(TEntity).FullName));
     }
 }
        protected override void OnDetect()
        {
            var factory = (NHibernateShardSessionFactory)RepositoryFramework.GetSessionFactoryByFactoryType(typeof(NHibernateShardSessionFactory));

            foreach (var shard in mysqlShards)
            {
                var session = factory.SessionManager.OpenSession(shard, null);
                var now     = session.CreateSQLQuery("SELECT NOW() d").AddScalar("d", NHibernateUtil.DateTime).UniqueResult <DateTime>();
            }
        }
        public IShardSession <TEntity> OpenSession <TEntity>(ShardParams shardParams)
        {
            var strategy = RepositoryFramework.GetShardStrategy(typeof(TEntity));

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy", String.Format("无法找到类型 {0} 对应的分区策略信息。", typeof(TEntity).FullName));
            }

            var shardId     = strategy.GetShardId(shardParams);
            var partitionId = strategy.GetPartitionId(shardParams);

            using (var scope = ProfilerContext.Profile("open nhibernate session"))
            {
                var session = manager.OpenSession(shardId, partitionId);
                return(new NHibernateShardSession <TEntity>(session));
            }
        }
Esempio n. 6
0
 public void RegisterRepository()
 {
     //初始化配置
     RepositoryFramework.Configure(this);
 }
        internal ISession GetSession()
        {
            var session = (NHibernateShardSession <T>)RepositoryFramework.OpenSession <T>(shardParams);

            return(session.InnerSession);
        }
        MongoSession GetSession()
        {
            var session = (MongoShardSession <T>)RepositoryFramework.OpenSession <T>(shardParams);

            return(session.InnerSession);
        }