ASP. NET MVC builds its own framework (i)

Source: Internet
Author: User

Website: https://www.cnblogs.com/sggx/p/4555255.html

Why do you have to frame yourself?

Big guy, don't worry, let me tell you slowly! There is no such feeling, from a job to another company, the company's framework is often different, so you have to abandon the original, learning a new framework.

The problem is that you get used to a framework, such as encapsulation extension methods, factory patterns, entity mappings, and so on, you use very well, but to move to the new company, you have to learn the framework of their company, often you on this

It will take a lot of time.

So I had the idea to build my own framework, my framework used entityframework6.0+asp.net MVC4+AUTOFAC, and the following is my frame structure:

Myframe.domain Entity Model layer

Myframe.datamapping Data Mapping Layer: Mapping entity classes and database table relationships, where the database context resides

Myframe.idao Data Access Interface layer

Myframe.dao Data Access Layer

Myframe.iservice Business Logic Interface layer

Myframe.service Business Logic Layer

Myframe.common Universal Expansion Layer

Myframe.web UI Layer

The reference relationship between layers and layers

  Domain (lowest layer) = "Each layer calls;idao=>dao,service; Iservice=>service; Idao,iservice=>web

Entity base class
MyFrame.Domain.DomainBase: The Entity base class, the entity class all needs to inherit the Domainbase, now this class only has two properties, and so on slowly expands the consummation

Domainbase

Data access base class interface 

MyFrame.IDao.IDaoBase: Packaging the method of adding and removing, and paging, etc.

Idaobase

Data access implementation base class

MyFrame.Dao.DaoBase: Need to inherit idaobase,idisposable

Daobase

Database Access Context

MyFrame.DataMapping.DataBaseContext

Databasecontext UserMap

Extended helper Classes

MyFrame.Common.Helper: Encapsulated a number of common methods, I use it more handy, increase their development efficiency

Helper

Pagination control

I used to be a pagedlist,nuget. Search installation Pagedlist.mvc, and then package themselves, encapsulated in Daobase selectpagelist ()

To make this control more extensible, write a partial attempt to _pagelist, define a paging model,

Why write for yourself instead of wrapping it yourself, because later pages may need to jump "home", "last", etc.

Pagelistmodel_pagelist

Pagination CSS

pagelist

How to invoke it? Just like calling the partial attempt method, it only needs to pass in a Pagelistmodel

ControllerIndex

AUTOFAC components

Control reversal, similar to the components of the IOC container, by configuring the interface to correspond to the specific implementation class

Then call we just need to tune the interface on the line, reduce the coupling.

Component NuGet has its own download and installation on the line

Configure in Globl.asax

View Code

Through the construction method in the controller, the call can be

View Code

In fact, the configuration interface corresponding to which specific entity relationship, should be placed in the config file is better, this later slowly optimization.

End

This is a primary version, the latter must be well-developed, such as joining transaction transaction management, sorting, conditional query and so on.

If you have any good suggestions, do not hesitate to promote each other's learning.

Reprint please indicate the source, thank you!

Source code: http://yun.baidu.com/share/link?shareid=2761504180&uk=2820969304

ASP. NET MVC builds its own framework (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.