リポジトリパターンの実装の下で試しました
interface IRepository<T>
{
IQueryable<T> All { get; }
T Find(object id);
void Insert(T model);
}
次に、IAdminRepository を以下で定義しています
interface IAdminRepository : IRpository<Role>, IRepository<User>
{
}
public class AdminRepository:IAdminRepository
{
IQueryable<User> IRepository<User>.All
{
get { throw new NotImplementedException(); }
}
User IRepository<User>.Find(object id)
{
throw new NotImplementedException();
}
void IRepository<User>.Insert(User model)
{
throw new NotImplementedException();
}
IQueryable<Role> IRepository<Role>.All
{
get { throw new NotImplementedException(); }
}
Role IRepository<Role>.Find(object id)
{
throw new NotImplementedException();
}
void IRepository<Role>.Insert(Role model)
{
throw new NotImplementedException();
}
}
私のビジネスレイヤーでは、インターフェイスベースの呼び出しを使用しています。
public interface IAdminService
{
bool CreateUser(User user);
List<User> GetAllUsers();
}
public class AdminService : IAdminService
{
private readonly IAdminRepository AdminRepository;
public AdminService(IAdminRepository _adminRepository)
{
AdminRepository = _adminRepository;
}
public bool CreateUser(User user)
{
AdminRepository.Insert(user);
return true;
}
public List<User> GetAllUsers()
{
return AdminRepository.All; // Here is error
}
}
エラー: IRepository.All と IRepository.All があいまいです。
これを解決するには?このようにリポジトリ パターンを使用するという私のアプローチの問題は何ですか?