Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Entity Framework with ASP.NET MVC Data Access Design Patterns Using the Repository Pattern

Joe Di Trolio
Joe Di Trolio
3,367 Points

Using the Repository Design Pattern for non-crud operations in an MVC application

Firstly, what a fantastic series!

I have a question concerning the Repository Design Pattern in an MVC application.

I understand that using a repository is a great centralised location for storing CRUD operations and interacting with a database.

However, is it considered a good design pattern for the same repository to also contain other kinds of operations - that don’t necessarily interact directly with the database?

For example, in my application, a controller uses a method in my repository to insert new information from a form into a database. However, the information must be manipulated first and that’s handle by a separate method.

FORM -> CONTROLLER -> METHOD 1 (Manipulate data) -> METHOD 2 (Insert data to db)

Where should this intermediary method (Method 1) ideally go in my application?

I hope my question make sense and please hesitate to let me know in case you need some clarification.

1 Answer

Steven Parker
Steven Parker
229,982 Points

Does it manipulate it and insert it? Or just manipulate it and sent it back? In the first case, it would seem entirely appropriate to handle it in the same controller. In the second case you might set up a separate controller, but if you're not doing a lot of that kind of thing you still may just keep it in the same controller for expedience.