Asp.net MVC + MongoDB + autofac to build a lightweight Blog system (1)

Source: Internet
Author: User
Tags support microsoft

Over the past two days, I 've been thinking about whether I can build a lightweight. Net blog publishing system... All things are lightweight. I want the system to be based on the Asp.net MVC Framework, so I chose the following components to complete this idea.

1. Entire ApplicationProgramArchitecture: Asp.net MVC 3 (razor)

2. Data Storage: MongoDB is a document-oriented database with multi-system support, lightweight, and high performance.

3. orm: If You Don't Need An ORM for application development, it seems a little old-fashioned, but the ORM will never be comparable to ado.net. If there is no chaos, it will be EF, nhib.pdf, or LINQ .... I want to use an ORM tool here, so I chose simple. Data, a very lightweight ORM tool, which uses the dynamic feature in C.

4. The IOC tool is definitely autofac, the most lightweight...

 

For Asp.net MVC, you can see a lot of learning materials here:Http://www.cnblogs.com/n-pei/tag/Asp.net%20MVC/

Including Asp.net MVC 3 SeriesArticle....

 

Environment requirements:

1. First, you need to install. NET Framework 4. You do not need to install Asp.net MVC on your machine. You only need to add the corresponding DLL to the bin directory.

 

2. If you have been familiar with MongoDB before, skip this section and go to step 3.

 

Http://www.mongodb.org/Its data is stored in JSON format.

Download to the corresponding compressed package and decompress it to a disk.

By default, Mongo does not create folders by itself, but it needs to find the specified folder data \ dB. Therefore, we need to create the following folders under the root folder where the bin directory is located:

 

The next step is to run the DB server.

 

Now the database server is running, because it runs in DOS, so this window cannot be closed, and how to set it as a Windows service will be explained in the future, in this way, the window needs to be opened.

 

3. orm: simple. data is a lightweight ORM tool that uses the C # dynamic attribute. It is not very useful, but it is fast and supports various databases without configuration files...

You can download it here:Http://github.com/markrendle/Simple.Data

 

4. IOC tool. This autofac has been introduced in many articles. Here you can download and view:Http://code.google.com/p/autofac/

Related Articles in my blog:Http://www.cnblogs.com/n-pei/tag/Autofac/

 

 

Maybe you are impatient. I am so jealous. Well, next I will start using mogondb. This article mainly introduces how to use it in Asp.net MVC .... Other modules will be introduced in future articles.

 

First, create an object. Here, only the post and comment entities are created.

Next, create the repository module:

Post repository interface:

Corresponding save method:

The operations here are complicated and will be optimized in combination with autofac later.

The getall method and the method used to obtain a post object by ID are as follows:

 

 

 

 

Another part is to update a post.CodeIt will not be pasted.

 

The following is the Controller code:

Create post code:

After adding the corresponding view, run:

Click craete:

Saved successfully, and then automatically jumps to the List page:

 

Wait for the entire project to be written. I will place the code on codeplex to support Microsoft.

 

 

 

 

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.