Build a distributed development system using the lightweight frameworks Nancy and Simple. Data (1)

Source: Internet
Author: User

Some people may think this title is a gimmick, because you don't know what Nancy is doing. If a foreign developer says that most developers on the Microsoft platform can select a development framework only between ASP. NET and ASP. net mvc. Nancy is independent of the two frameworks. It uses Ruby for reference.

Let's take a look at an example to illustrate how to use NancyFX:

Create an ASP. NET (MVC) Empty solution. If it is an empty solution of ASP. net mvc category, remember to comment out the route in the Global. asax file. Nancy has its own routing mechanism.

Using Nancy, it adds its own HttpHandler to the configuration file.

 

 

Next we will see how to return different results through Nancy through different URL requests.

 

1. If there is no URL parameter:

 

First, create a defamodule module. cs to inherit the base class NancyModule.

 

Run the program after compilation. The result is as follows:

 

Let's take a look at how to obtain these parameters in some complex URL requests:

Set our request to url +/Fristname/lastname, then define a Nancy Module to parse the url and return information:

Create a class named WelcomeModule. cs:

Request by URL +/firstname/lastname, the result is as follows:

 

Of course, this is simply to return some characters, and the URLs are relatively simple. In addition to these simple URL formats, Nancy also supports regular expression URL requests.

In addition, Nancy also supports the Razor view engine. It expands the View rendering mode based on Razor.

 

Similar to ASP. net mvc, but here the View is rendered through Module. Now we define a Model as Person, which has two attributes: FirstName and LastName. How can we bind this Model to a page through Nancy?

First, you need to define a Model:

 

Defines a PersonModule that inherits the NancyModule;

 

The defined page is Person. cshtml, So we add a Razor page and dynamically bind the person to the page:

 

All the requests described above are Get requests, and Nancy also supports other HTTP requests such as Post. If Big Data is returned, Post requests are still required.

 

Apart from Nancy, it is Simple. Data. I have previously introduced this lightweight ORM tool (not even an ORM ).

My favorite ORM tool-Simple Data

 

 

 

 

 

 

 

 

 

 

 

 

These two lightweight frameworks share a common feature, that is, to make some basic processing independent. Therefore, it is suitable for distributed development. For example, Nancy can stop route configuration or unified configuration. Instead, each module can write its own route.

Simple. Data seems to use the Dynamic feature, so the database interaction between each module can be very independent.

 

The above is the framework I need to use. The next article describes how to establish the basic modules of distributed development in the future.

 

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.