Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

asp.net mvc - How to structure an enterprise MVC app, and where does Business Logic go?

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

  • Controller: deals with routing requests
  • View: deals with presentation of data
  • Model: looks a whole lot like a Data Access layer

Where does the Business Logic go?

Take a large enterprise application with:

  • Several different sources of data (WCF, WebServices and ADO) tied together in a data access layer (useing multiple different DTOs).
  • A lot business logic segmented over several dlls.

What is an appropriate way for an MVC web application to sit on top of this (in terms of code and project structure)?

The example I have seen where everything just goes in the Model folder don't seem like they are appropriate for very large applications.

Thanks for any advice!

question from:https://stackoverflow.com/questions/2568010/how-to-structure-an-enterprise-mvc-app-and-where-does-business-logic-go

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...