ASP. WebForm scaffolding combined with generic Unit of work & (extensible) Repositories Framework Code Generation Wizard
The code structure generated in the last release using the simple repositories pattern is a bit cumbersome and complex, and the entire project hierarchy is unclear, and in the development process there is a lot of logic code written in the Apsx.cs, feeling a bit nondescript. The Generic Unit of Work & (extensible) Repositories Framework project, recently seen on CodePlex, is very popular.
Generic Unit of Work & (extensible) Repositories framework is a very lightweight extension to EntityFramework and uses a unit of work dependency injection design patterns, The structure of the entire project is very normative and the logical hierarchy is very clear, View (WebForm), Business logic (service)-〉 entity (ORM)->database.
Let's take a look at the effect of actual use
Environment configuration
Demo Source Code Http://files.cnblogs.com/neozhu/unitofworkTutorials.zip
CodePlex Open Source Project http://genericunitofworkandrepositories.codeplex.com/
Git ASP. WebForm Scaffolding Project Source code https://github.com/neozhu/WebFormsScaffolding/tree/UnitOfWorkRepository under this branch
In addition to referencing Repository.pattern,repository.pattern.ef6,service.pattern in a new Web project, you need to add the following references using NuGet:
Commonservicelocator 1.3
Unity 3.5
Webactivatorex
Unity.webforms
The system will automatically generate UnityWebFormsStart.cs after adding unity.webforms
Next do a demo
Code-first Entity
Company--Department
Company entity Class Department entity Class 1 to many
New entity class must inherit entity
Create a new DataContext
When the basic work is done, here's the survival code.
ADD Scaffolding Item Select Web Forms Pages Using entityframework
First survive a company entity's additions and deletions 4 pages and a companyrepository, a companyservice The Repository class is generated by an entity that contains a pair of many-to-one relationships that generates data that gets a child table through a foreign key or primary key
For example, the department entity generates a sub-department through the ParentID foreign key, obtains the department through the company and obtains all the child departments according to the primary key method.
After the code is generated, the next thing you need to do is unity to configure the ingress of dependency injection
Open UnityWebFormsStart.cs
Complete the configuration. Generate Companyservice,companyrepository and Departmentservice,departmentrepository join
Take a look at the page section of the code, the default paging query and delete method
Template-generated page styles fully use Boostrap CSS
New style of page
Edit the page, the system will automatically generate the self-associated child table additions and deletions to the function, the child table additions and deletions through the popup way pop-up, specific background code please refer to the demo source code.
Please like:) If you find it useful.
ASP. WebForm scaffolding combined with generic Unit of work & (extensible) Repositories Framework Code Generation Wizard