MVC framework construction and mvc Framework Construction

Source: Internet
Author: User

MVC framework construction and mvc Framework Construction

1.0 initial establishment of directories and projects

 

 

2.0 configure references between layers

IRepository Reference Model
Repository references Model, IRepository
IServices references Model, IRepository
Services references Model, IRepository, and IServices
Site references Model, Common, IServices, WebHelper
WebHelper references System. Web. Mvc, IServices
Common Reference: system. web, system. web. Extensions

3.0 add an ADO. NET object data Model to the Model layer

The Repository project of the Dal layer references EntityFramework. dll (find the dll in the Model layer), System. Data. Entity
In the Repository project, create a class: BaseDbContext
Content:
Using System. Data. Entity; // This namespace is required to inherit DbContext.
Public class BaseDbContext: DbContext
{
Public BaseDbContext ()
: Base ("name = see App. Config" Here) // See <connectionStrings> <add name = "JKCRMEntities"/> </connectionStrings>
{
}
}

Delete two files in the Model layer

 

4.0 create parent classes

The IRepository layer establishes the IBaseRepository interface --> For details, see ibaserepositoryinterface .txt.

Repository BaseRepository-> For details, see baserepository.txt (set the thread cache so that all the dal in a thread can share an EF container)

IServices layer interface IBaseServices --> For details, see ibaseservicesinterface .txt.

Services Layer creation class BaseServices --> For details, see baseservicescategory .txt.

Put BaseDbContext. cs and so on in the new base solution folder.

 

5.0 use of T4 templates

Test --> find an object, create IRepository, IServices, Repository, Services, or directly use the T4 template to generate six files. Change the edmx position in the T4 template.

Create a controller for testing (note the constructor) --> autofac is not configured and will fail.

 

6.0 add AutoFac

Copy AutofacLibs to solution. Reference 2 dll
Create a class AutoFacConfig in App_Start. For details, see autofacconfigclass .txt. Note: You need to change the name of the three namespaces.
Register AutoFacConfig. Register ();

7.0 project configuration

Set the startup Item Site; set the webconfig string to be connected; set the location where the Services layer and Repository layer are generated. .. \ WLFHP. Site \ bin \

Test whether OK

8.0 others

Create BaseController reference system. web. mvc --> which contains various IServices

Related Article

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.