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