/// <summary> /// 创建一个实体类型的仓库。 /// </summary> /// <param name="entityType"></param> /// <returns></returns> private EntityRepository DoCreate(Type entityType) { //先尝试在约定中寻找实体类型自己定义的仓库类型。 var metrix = EntityMatrix.FindByEntity(entityType); var repoType = metrix.RepositoryType; if (repoType != null) { if (repoType.IsAbstract) { throw new InvalidProgramException(repoType.FullName + " 仓库类型是抽象的,无法创建。"); } var repo = this.CreateInstanceProxy(repoType) as EntityRepository; //EntityRepository repo; //if (RafyEnvironment.Location.ConnectDataDirectly || repoType.IsSubclassOf(typeof(MemoryEntityRepository))) //{ // repo = Activator.CreateInstance(repoType, true) as EntityRepository; // if (repo == null) // { // throw new InvalidProgramException("{0} 类型必须继承自 EntityRepository 类型。".FormatArgs(repoType)); // } //} //else //{ // repo = _proxyGenerator.CreateClassProxy(repoType, RepositoryInterceptor.Instance) as EntityRepository; //} var repoDataProvider = DataProviderComposer.CreateDataProvider(repoType); repo.InitDataProvider(repoDataProvider); repoDataProvider.InitRepository(repo); return(repo); } throw new InvalidProgramException(entityType.FullName + " 类型没有对应的仓库,创建仓库失败!"); //实体类必须编写对应的 EntityRepository 类型,不再支持生成默认类型。 ////如果上面在约定中没有找到,则直接生成一个默认的实体仓库。 //return this.CreateDefaultRepository(entityType); }
/// <summary> /// 创建一个实体类型的仓库。 /// </summary> /// <param name="entityType"></param> /// <returns></returns> private EntityRepository DoCreate(Type entityType) { //先尝试在约定中寻找实体类型自己定义的仓库类型。 var metrix = EntityMatrix.FindByEntity(entityType); var repoType = metrix.RepositoryType; if (repoType != null) { if (repoType.IsAbstract) { throw new InvalidProgramException(repoType.FullName + " 仓库类型是抽象的,无法创建。"); } var repo = Activator.CreateInstance(repoType, true) as EntityRepository; if (repo == null) { throw new InvalidProgramException(string.Format( "{0} 类型必须继承自 EntityRepository 类型。", repoType )); } var repoDataProvider = DataProviderComposer.CreateDataProvider(repoType); repo.InitDataProvider(repoDataProvider); repoDataProvider.InitRepository(repo); return(repo); } throw new InvalidProgramException(entityType.FullName + " 类型没有对应的仓库,创建仓库失败!"); //实体类必须编写对应的 EntityRepository 类型,不再支持生成默认类型。 ////如果上面在约定中没有找到,则直接生成一个默认的实体仓库。 //return this.CreateDefaultRepository(entityType); }