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

前端 未结 8 1471
夕颜
夕颜 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条回答
  •  旧时难觅i
    2020-12-12 15:51

    In my apps, I usually create a "Core" project separate from the web project.

    Core project contains:

    1. Business objects, such as entities and such
    2. Data access
    3. Anything that is not specifically designed for web

    Web project contains:

    1. Controllers, which route requests from the UI to the core logic
    2. Views, which focus on presenting data in HTML
    3. View Models, which flatten/transform core business objects into simpler structures designed to support specific views

    The key point here is that the web-based Models folder/namespace is ONLY used for presentation-specific models that document the specific variables needed for a given view. As much "business logic" as possible goes into the core project.

提交回复
热议问题