Search code examples
asp.net-mvcbusiness-logic-layer

MVC architecture large action method on controller


I'm currently developing business logic in a Controller's ActionResult function, and I've noticed it's becoming unwieldy... large... involves a lot of page ups/downs.

Code includes populating lists for dropdownlists assigned to ViewBag properties, but most of the size is taken up EF (linq to entities) and in memory processing of this. And finally sent to a view model via Auto Mapper.

Where is the best place to move this code? In another class in the Controllers folder? Or in another class in another folder, i.e. a Business layer?


Solution

  • Separate you project to :

    • WebUI(View, Controller-A MVC Project)
    • Business Layer(Holds Business Logic - A class Library Project )
    • Data Access Layer(Holds Entity Model(May be EDMX) - A class Library Project)

    A controller of WebUI project call method of business layer. If business need data from database then, it will call Data Access Layer.