我想根据一个标志返回两个仓库实例中的一个。我的仓库接口和实现如下:
public interface IRepository<T>
{
T Insert(T entity);
void Delete(T entity);
IEnumerable<T> SearchFor(Expression<Func<T, bool>> predicate);
IEnumerable<T> GetAll();
T SearchForFirst(Expression<Func<T, bool>> predicate);
bool Has(Expression<Func<T, bool>> predicate);
}
class Repository<T> : IRepository<T> where T : class { ... implementation here ...}
返回存储库两个实例之一的方法应该类似于:
public IRepository<T> GenerateRepository(bool flag)
{
if ( flag ) {
return new Repository<MyFirstType>();
} else {
return new Repository<MySecondType>();
}
}
有谁能指点一下我,关于这个应该如何编写的正确方向是什么?
谢谢