I was wondering what is the best practice for enterprise level architecture based on MVC5. I mean selection between multiple layer or multiple project in one solution? and or maybe more than one solution? any good example project?
相关问题
- Shared common definitions across C/C++ (unmanaged)
- How to generate URL for the action with attribute
- How to retrieve multiple columns from non-entity t
- Asp.Net MVC 5 Identity Create Database Admin Inter
- Unable to login to PiranhaCMS after setup
相关文章
- Why do I need a ToList() to avoid disposed context
- SSIS solution on GIT?
- Cannot implicitly convert Web.Http.Results.JsonRes
- Why doesn't there exists a subi opcode for MIP
- DDD Architecture - Where To Put Common Methods/Hel
- “Trust relationship between … and the primary doma
- Proper scenekit architecture for multi level/scree
- MySQLi Error Handling?
Take a look at Contoso University. Excellent example of Enterprise level application.
Sample Web Application Demonstration
Since my question has been visited a lot in the last year and there is no solid answer as I am aware of that, I decided to provide a comprehensive answer as much as possible. This answer is based on some actual projects experience and with few expert consultations:
right
and if it doesn’t, it iswrong
. There are no rigid principals in software design. There areProject needs and specifications
. But generally, it has been accepted usingDesign Patterns and Principles
makes project morerobust
,reliable
andeasy to maintain
and make your codeloosely coupled and highly cohesive
.Software Design and Architecture
is about how you could manage your project easily and how you could maintain your future changes. Think about which approach gives you best answer on them. That will be the best for you. Don't think too much aboutProfessionalism
! .Your project grows by time and gets more mature. So just think about your project!Separation of Concerns
orSoC
. It means you should have different tiers for different layers of your project. It is highly recommended to use different project in your solution forData Access Layer
,Domain Entities
,Business Layer
andPresentation Layer
. In MVC5 project, it is better to useClass Library Project
forData Access Layer
,Domain Entities
,Business Layer
and a MVC project forPresentation Layer
.Data Access Layer
is the project that faces to database and database interactions. You could have all yourEntity Framework
or similar entities in this project. Having separated layer for database layer means in the case of changing your project data warehouse, the only thing you need to change is changing this project and some minor changes on yourBusiness Layer
. All other projects in your solution remain intact. So you could easily move from MS Sql to Oracle or fromEntity Framework
toNHibernate
.Domain Entities
is the project I use to define all my solution level interfaces, classes, enums and variables. This project keeps integrity throughout my solution on my classes and my methods. My all classes in whole solution are inherited from interfaces in this project. So I have one place to change my classes or global variables and it meansEasy to Maintain
for future in my solution and easy to understand for newly joined developers to the project.Business Layer
is the place I put my all business logic includingBusiness Entities
andBusiness Services
. The whole idea about this layer is having one place to keep your all business methods and interactions. All calculations, object modification and all logic about data including saving, retrieving, changing and so on should happen in this section. By having this layer in your project, you could have different consumers at the same time, for example one nativeMVC
and oneWeb API
layer. Or you could provide different feeding based on different business services consumers specifications. It is highly recommended to avoid putting any business logic into controller section of MVC layer. Having any business logic inside controllers means you using your presentation layer as business logic layer and it violatesSeparation of Concerns
. Then it won’t be easy to change from one presentationlayer to other or having different type of consumers for your solution. It is better to keep controller section in MVC as slim as possible. The controllers should only have logic and methods directly related toView Models
. For more information aboutView Models
refer to section7
. One thing to remember, It is better to have differentBusiness Services
classes based on your solution objects orBusiness Entities
.Presentation Layer
in MVC solution will be an MVC project. But solution could have other type or more than one Presentation Layers for different consumers or technology. For example you could have one MVC layer and oneWeb API
in one solution. Generally Use Presentation Layer to keep all presentation logic in it. Presentation logic shouldn’t have anything related to business logic or data logic. So question is what isPresentation logic
?Presentation logic
is logic related to view models. View models are objects customized for views or pages. In most cases, business objects are not suitable to use in views. On the other hand, presentation views usually need some validation logic or presentation logic, for example display name different than original object names. In these cases it is better keep presentation logic separated than business logic to make it easy to change presentation logic or business logic independently and even easy to switch presentation layer for different UI design or changing business logic for having more functionality without fear of any interruption with presentation logic. In the case of using MVC project as presentation layer for solution, all view models should be places inModels
section of MVC project and all presentation logic should be placed inControllers
section of project.AutoMapper
,BLToolkit
, andEmitMapper
.Last word: please comment and score
question
and myanswer
to make it better!