I ran some searches but found no available answer to this issue.
Okay, my MVC 3 architecture is like this:
- Project.EDM (contains only the entity framework edmx file and its .tt and .cs entity classes)
- Project.DAL (contains IXxxRepositiory and XxxRepository where CRUD is performed on the entity classes)
- Project.Web (the MVC3 project. Controllers transfer data from ViewModels into entity models and call the CRUD functions in the DAL repositories.)
The WebApi
in MVC4
appears so attractive since we will be able to call the CRUD operations from other applications. We all love this idea.
But the existing examples I have found have the CRUD operations inside the MVC4 project under ApiController
. I am used to putting these operations into a separate DAL project. What is the recommended choice? Can we still have a separate DAL class? How do you experts design the architecture?
Thank you for all helpful advice.
What I do is this:
So both the UI and the API will have one or multiple services, that in turn have one or multiple repository objects.
The only reason why most examples directly query the database from the ApiController is probably because of simplicity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With