简体   繁体   中英

Asp.net MVC layered Architecture

I am new in Asp.net MVC.i have created mvc application using datasource but i want mvc application using n tier architecture..same as like asp.net application generally they have Presentation layer Busineess layer and Data Layer.

I want to create mvc Application using n tier architecture...any help or demo link which followed mvc n tier architecture..

Your ASP.NET MVC controller can talk to whatever classes you have in your n-tier application.

For example, your ProductsController would call your ProductsBusiness layer, which would call your ProductRepository which in turn queries the database.

Your controller should be very this, so there shouldn't really be too much logic in there. One way to look at it is to imagine you had to replace the entire ASP.NET MVC UI layer - so anything you want to reuse should be lower down. Another way to visualise this is to imagine writing a second UI that needs to re-use the business layer to do all the same things.

So your controller in your MVC application is a layer above your other n-tier layers.

https://templatestack.azurewebsites.net/Templates/GetAll provides a lot of examples of N-tierd applications for different templates

Shortly most of the templates are with similar structure:

在此处输入图片说明

Data - data layer

  1. Project for the database tables contains the Db Context and the configurations of the migrations

  2. Project for abstraction levels over the database - contains implementation of different abstraction levels over the database like Unit of work and Repository pattern

  3. Project for the database models - contains all the db models including these from the ASP.NET identity which are moved from the web project

Services -logic layer

  • Contains the business logic for your application

Tests

Tools

  • Here different console apps like Crawlers, Importers and etc. might be created

Web Tools - web application layer

  1. Project for the web application - this is the classic MVC project which is stripped of the Db context dependency as well as the db models dependencies . Contains configurations for the Dependency Injection, Automapper and other external libraries. The architecture is supposed to keep all your controller actions very tiny and do all of your business logic in the services, which are injected by your IoC (inversion of control) container. In our case this is Autofac

  2. Project for the web application infrastructure - this project contains source code which is related to the Web application, but might be reusable, and this is why it is separated by the Web App. For example here we can put our View Models, custom filters and annotations, html extension methods and helpers, and etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM