ASP. NET Core 1.0 Foundation and application launch

Source: Internet
Author: User
Tags dotnet

. NET Corehttp://dotnet.github.io/[HTTPS://GITHUB.COM/DOTNET/CORECLR]
ASP. NET Core 1.0 https://get.asp.net/
Documentation:https://docs.asp.net/en/latest/index.html
MVC:https://docs.asp.net/projects/mvc/en/latest/overview.html
EF:http://docs.efproject.net/en/latest/

win under Install Vs2015sp1 Https://www.visualstudio.com/downloads/download-visual-studio-vs , the default installation of Microsoft Web Developer Tools, which is AspNet5.ENU.RC1_Update1, will be renamed after the ASP. NET Core 1,dnx is migrated to the CLI.

Project Structure

Compared to the previous changes, the project extension changed from csproj to Xproj,web.config Appsetting.json, the default uses the package management tools such as NPM and Bower, gulp and other front-end management tools, using DNX 4.5 and Dnx Core 5.0来 supports the. NET Framework and cross-platform. NET Core.

Startup class
 Public classStartup {/// <summary>     ///configuration Information/// </summary>      PublicIconfigurationroot Configuration {Get;Set; } /// <summary>     ///Program Entry point/// </summary>     /// <param name= "env" ></param>      PublicStartup (ihostingenvironment env) {varBuilder =NewConfigurationbuilder (). Addjsonfile ("Appsettings.json")                      .         Addenvironmentvariables (); Configuration=Builder.     Build (); }    /// <summary>     ///Configure the service/// </summary>     /// <param name= "Services" ></param>      Public voidconfigureservices (iservicecollection services) {services. Addantiforgery (). Addcaching (). Addlogging ().         Addmvc (); /*Services. Addentityframework (). Addsqlserver (). adddbcontext<apbcontext> (options = options.          Usesqlserver (connection)); */     }    /// <summary>     ///Configuring Components/// </summary>     /// <param name= "app" ></param>     /// <param name= "env" ></param>     /// <param name= "Loggerfactory" ></param>      Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory loggerfactory) {//using LogsLoggerfactory.addconsole (Configuration.getsection ("Logging"));         Loggerfactory.adddebug (); //whether to debug mode        if(env. Isdevelopment ()) {app.             Usebrowserlink (); App.         Usedeveloperexceptionpage (); }         Else{app. Useexceptionhandler ("/home/error"); } app.         Useiisplatformhandler (); //working with static filesapp.         Usestaticfiles (); //using MVCApp. USEMVC (routes ={routes. MapRoute (Name:"default", Template:"{controller=home}/{action=index}/{id?}");     }); }    /// <summary>     ///Configuring the Startup class/// </summary>     /// <param name= "args" ></param>      Public Static voidMain (string[] args) = webapplication.run<startup>(args);}

1) The Startup method is the startup entry for the entire program, similar to Global.asax, which is bound to a configuration property after the underlying configuration information is initialized in the constructor.
2) The Configureservices method is the core of the dependency injection, the default parameter services, you can also register a dependency injection custom type, while the need to start some functions also need to be opened here, such as adding MVC, Cache, log module, etc. need to add the following code:

Services. Addantiforgery ()              . Addcaching ()              . Addlogging ()              . ADDMVC ()

In the new version of ASP. NET Core 1.0, the majority of modules in addition to the most basic modules are implemented in a modular manner, that is, the official GitHub has a lot of module source code, to enable these components first to add the module to use. If you enable the EF module:

Services. Addentityframework ()               . Addsqlserver ()               . Adddbcontext<ApbContext> (Options and options). Usesqlserver (connection));

3) The Configure method is to configure the added components, such as using the MVC feature and configuring the route:

App. USEMVC (routes =           {                routes. MapRoute (                    "default",                    "{controller=home}/{action =index}/{id?} " );            });

ASP. NET Core 1.0 Foundation and application launch

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.