Nhibbench-based unitofwork + repository mode (autofac)-Part1

Source: Internet
Author: User

Recently I wrote a series of unitofwork and repository ModesArticle, You can view these articles here...

Http://www.n-pei.com/blog/unitofwork-for-nhibernate

Http://www.n-pei.com/blog/unitofwork-for-nhibernate-part2-nic

Http://www.n-pei.com/blog/unitofwork-for-nhibernate-part3-nic

Http://www.n-pei.com/blog/repository_pattern_nhibernate

IOC tools are essential for us to focus more on system design .. So here I will use autofac, Asp.net MVC, and nhib.pdf to give a simple example.

First, create an Asp.net MVC Project (MVC2 ).

Add the previously created unitofwork and repository projects.

Next, add a productcontroller In the MVC project.

Add the nhib.pdf configuration file:

With the configuration file, we can create our install view.

First, create a table in the corresponding database through schema, and then insert several data records in the database .....

View:

Run install:

  

The above uses the unitofwork mode to insert records.

Next we will use repository to add a product record.

First, the Controller partCode:

View code:

Add a record. Try again,

Set breakpoints:

In addition, you can use unitoofwork sessions to query products or use repository to query prodct;

In the following article, I will combine autofac with repository optimization to make the code more concise and implement IOC.

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.