Last post Aug 16, 2015 10:48 AM by bweber89
Aug 14, 2015 02:20 AM|rpk2006|LINK
I am new to Design Patterns and trying to implement Repository Pattern in MVC 5 application.
I am referring a post:
CRUD using Repository Pattern
The example uses DBContext Class because it is using Entity Framework. I am using ADO.NET directly instead of EF.
From the post what I understood is:
I want to know what is the use of creating an Interface. Why can't I have the BookRepository class only with the CRUD methods.
What exactly Interface is doing?
Is there any better example of Repository Pattern?
Aug 14, 2015 02:52 AM|mostafasydney|LINK
Please refer to the post for the advantage of using Interface in repository pattern (assuming you know the advantage of using Interface): http://stackoverflow.com/questions/11326786/advantage-of-using-interface-over-abstract-class-for-repository-pattern
You can have a look this post: http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-and-entity-framework.htm
Hope this will help.
Aug 14, 2015 04:56 AM|MaheshKumarCh|LINK
The advantages of repository pattern is
You might not be seeing advantages of repository pattern at theory level, once if you start developing this, you feel the advantages of this pattern.
Aug 16, 2015 10:48 AM|bweber89|LINK
The reason for creating an interface for the repository class is simply to decouple the repository from a controller. As an example, you could use ninject or any other DI container to inject any implementation of IBookRepository allowing you to unit test
the controller should you wish to do so.
It is considered a 'good practice' and ultimately one of the SOLID principles to decouple concrete implementations from dependent classes.
I hope thinks makes sense to you, if not, please let me know and I'll gladly provide an example