I am a beginner to the ASP.Net MVC. After reading many tutorials and digesting its concepts, I have yet to see an approach that clearly demonstrates where does the business logic go.
My app will have a lot of use of jQuery AJAX usage (which will be calling Controller's Actions for various purposes such as dependent interaction, validation). I will definitely use the ViewModel concept, but I am still unclear where the business logic should reside. I do not want to put in the controller or a model. Should I put it in a separate service layer?
I think you pretty much answered your own question, in a separate project.
Not in the controllers and absolutely not in the models.
Edit: Notice that the controller is highly coupled with the httpcontext so it will be a very smart thing to move the logic layer to a different dll-layer.
The M in MVC is everything that are used to fetch and process the information that you use in your application. The business layer is therefore a part of it.
I would just start by creating a separate class library and put all of my logic in it. As long as your classes are fairly small and has a clear responsibility it's quite easy to refactor later if you need a separate webservice (another project needs access to the data).
I usually create a third class library and put all definitions in it (service interfaces and the domain models). by doing so you'll follow the separated interface pattern and make it even easy to swap the implementation later on (and to test your business layer)
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