How to structure an enterprise MVC app, and where does Business Logic go?

前端 未结 8 1413
夕颜
夕颜 2020-12-12 15:05

I am an MVC newbie. As far as I can tell:

  • Controller: deals with routing requests
  • View: deals with presentation of
8条回答
  •  春和景丽
    2020-12-12 15:38

    "It Depends" :)

    Requests are routed to controllers, which handle them appropriately. Controllers are the "glue" that holds everything else (Models, Views, etc) together. So it is natural that "business logic" would be either processed directly or offloaded to another component by a controller.

    Where you actually put the logic depends on your needs. If logic is only needed by a single controller then putting it directly inside of one is fine. Of course, logic might also go into a single model if it is required for data consistency.

    Alternatively you can put logic in helper classes/functions, or (as others have mentioned), you can create a services layer for the business logic.

提交回复
热议问题