2

I have implemented IRepository interface for multiple domains but I don't know how to call specific method.

Below is the code :

public interface IRepository<T> where T : class
{
    IEnumerable<T> GetAll();
    void Add(T entity);
    void Update(T entity);
}


public interface IProjectRepository : IRepository<ProjectType>, IRepository<Project>, IRepository<ProjectDetail>
{
}

public class ProjectRepository : IProjectRepository
{
// implemenation

}

Now, When I create object of ProjectRepository class it shows all methods of interface but only expecting projecttype parameter.

I don't know, is it correct way of implementation? or Is there another way to implement similar thing?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Jagz W
  • 855
  • 3
  • 12
  • 28

2 Answers2

4

Generic repository IRepository<T> is not a good solution IMO, take a look at http://www.sapiensworks.com/blog/post/2012/03/05/The-Generic-Repository-Is-An-Anti-Pattern.aspx

I think it's better to specify each repository separately without generic paramter and common methods (are you sure you will always need Add, Update, GetAll in all of your repositories?)

EgorBo
  • 6,120
  • 3
  • 35
  • 40
  • It's a very, very moot point. Especially, considering how this is stated in the blog you referred. – Dennis Nov 15 '13 at 10:21
0

I think it can be better to create Generic repository with Unit of Work pattern.
Take a look at
http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
this is good tutorial about implementation Generic repository with Unit of Work
And at http://contosontiermvc.codeplex.com/SourceControl/changeset/view/13936#ContosoUniveristy/ContosoUniveristy/Controllers/CourseController.cs
.this is code example

alinaish
  • 456
  • 2
  • 7
  • 18