TAURUS.MVC support for ASP. NET Core Process

Source: Internet
Author: User

Objective:

These days, it seems that news and articles about. NET core are often in front of my eyes ~ ~ ~

Yesterday, Microsoft released it again. Core 2.1, Wandering Daze again, almost did not blind my eyes.

Well, it's probably a hint from heaven, after all, Cyq. Data has long been supported on. The core.

And TAURUS.MVC, estimate also make wronged, OK, merciful of pity see you once, give you on ASP.

It's not a very careful study of. NET core, this thing, only the home computer has VS2017 environment, so only at home research.

In the middle stop and walk, think of N days, and finally used more than 30 years of hand speed, knocking on the day and night code, finally saw the eyes of the light.

The following first share with the next experience ~ ~ ~.

How does TAURUS.MVC support. NET Core?

For TAURUS.MVC, its core is two DLL projects:

Cyq. Data has been supported on. NET Core.

Just deal with the Taurus.core project and support. NET Core just fine.

It feels so simple to think about it.

The code inside, not much, should not be as cyq.data support. NET Core.

Where do you get this from? ~ ~ ~

Thinking process, the Taurus.core project is rewritten for. NET core?

Taurus.core, and Cyq.data different, after all taurus.mvc=cyq. Data+taurus.core:

Cyq. Data is a database operations group image, although EF is much more powerful, but after all, it does not involve the program initiation process. Taurus.core, a custom MVC world opened from Ihttpmodule,ihttphandle to the portal

Build a demo to see the project for ASP. NET Core:

It starts from program, isn't that an EXE?

Then to startup:

  Public classStartup {//This method gets called by the runtime.        Use this method to add services to the container. //For more information on how to configure your application, visithttps://go.microsoft.com/fwlink/?LinkID=398940         Public voidconfigureservices (iservicecollection services) {        }        //This method gets called by the runtime. Use this method to configure the HTTP request pipeline.         Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env) {}

Also includes a service service and a stack of use-mode inter-piece configurations.

Online article service service called, what is the ghost, is the operating system process services?

Think more ~ ~ ~ a DIME has no relationship, others just like to call this name.

Therefore, the first topic of the study is: the difference between the startup mode of the traditional ASP.

In other words: IHttpModule, IHttpHandler and startup are different.

Light This topic, scattered on a lot of articles, the middle also separated a lot of time.

After half a bucket of water to understand, find out how big the world, the difference is so big, can only rewrite it?

have been concerned about my blog good people know that I maintain the fine frame too much, see: https://github.com/cyq1162

So, if the same framework is to maintain two different versions of the source code (. NET core version and non-. NET core version), I'll hurt the egg.

So, when you look at the. NET Core write-compatible code, the heart Will spit groove Microsoft egg pain, good compatibility? the heart ripples up the lost grass mud horse!

Later, a voice in the heart, noisy, too noisy, put it down, put it down ~ ~ ~

Cyq. Data supports. NET Core mode of peripheral vision once again God down

Remember that year:

When thinking about Cyq.data support for. NET Core,

It's been a sleepless day for countless days,

A slow motion in the right hand of the night

After constant thinking and experimentation,

Finally touched the heavens,

Pure Light the sudden drop,

The Final Solution,

Very shiny.

That is:

Put all the incompatible code, you slowly fill it up, it is a very brain-heavy physical activity:

Therefore, when all compatibility code is complete, the original Cyq.data code line does not change.

As soon as the complete Compatibility folder is included in the project, it is magically supported on. NET Core.

The same can be proven: look at the following to see how much to complete the compatibility code required!

TAURUS.MVC support for. NET Core Compatibility Code complete: System.Web.HttpContext Series compatibility code

Looks a lot, the basic core of all to fill, but also a cost brain of physical activity, brother's night life, you have been defeated the time ~ ~ ~

In this process, there have been some of the following problems with pits:

1: In Taurus.mvc core, is it the HttpContext to deliver the core version, or the web version HttpContext?

A: Use the Web version (let tradition be continued, save the learning cost)

2: For Httpcontext,httpresponse,httprequest, is it to inherit or not to inherit?

A: There is no inheritance, because there is no inheritance, and some property names have conflicting return values.

3:asp.net The core directory structure path and the traditional way of differentiation.

A:. NET core distinguishes between executing directories (DLLs and EXE directories) and resource directories (wwwroot), and tradition is a root directory and bin directory.

4: Other such as: File upload, path rewrite, Cookie, codec and other processing.

A: Basically, the location of the method used is shifted.

After a very strong, finally solved the problems encountered above.

These rewritten source codes have been submitted for submission.

See also: Https://github.com/cyq1162/cyqdata/tree/master/DotNetCore

However, the above rewrite is packaged in Cyq.data Core,

After all, there are some, on the way to fill a few more,

Facilitates subsequent support for the. NET core version of ASP. Aries.

Taurus.core project, only one middleware file was appended

Look at the figure code:

The original code line is not moved, a new middleware: TaurusMiddleware.cs

Middleware source code, because not submitted, here first put out:

usingCyq. Data;usingMicrosoft.AspNetCore.Builder;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.AspNetCore.Http;usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading.Tasks;usingTaurus.core;namespacemicrosoft.aspnetcore.http{/// <summary>    ///to support files that exist with ASP. NET Core/// </summary>     Public classTaurusmiddleware {Private ReadOnlyrequestdelegate Next;  PublicTaurusmiddleware (requestdelegate next) { This. Next =Next; }         Public AsyncTask Invoke (HttpContext context) {Try{System.Web.HttpApplication.Instance.ExecuteEventHandler (); //Processing Information                 awaitNext (context); }            Catch(Exception ex) {log.writelogtotxt (ex); }        }    }     Public Static classtaurusextensions { Public StaticIapplicationbuilder Usetaurusmvc ( Thisiapplicationbuilder Builder, ihostingenvironment env) {            //execute once to register the eventUrlrewrite URL =NewUrlrewrite (); Url.            Init (System.Web.HttpApplication.Instance); Appconfig.webrootpath= env. Webrootpath;//to set the root address, the root directory of Aspnetcore is not the same as other applications.             returnBuilder. Usemiddleware<taurusmiddleware>(); }    }}

The specific code is divine code meaning, do not explain, understand. NET Core Getting started will understand.

Use of TAURUS.MVC Middleware (advance notice):

After introducing Cyq.data and Taurus.core (DLL or source project), the introduction code of the middleware:

Add these three lines of code, and after introducing the context and TAURUSMVC, run a look at the effect (too beautiful, two are good):

1:

2:

Everything works perfectly, of course, these are the credit of the inner sperm worms.

Summarize:

In the development of ASP. NET core, this way: whether it's MVC or Web API,

Microsoft is all: ASP. Core+ef

Today, we have one more choice: Taurus.mvc+cyq. Data.

The latter, under the premise of inheriting the cross-platform, retains the traditional high-performance mode and saves the learning cost.

The official release, to be collated, should be next week.

PS: Long time did not write it even entrepreneurial series of articles, I do not know people still know that I am not in business?

TAURUS.MVC support for ASP. NET Core Process

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.