官术网_书友最值得收藏!

Installing the ASP.NET Core NuGet Package in Your Application

We'll straight away jump to installing the ASP.NET Core NuGet package in your application.

Follow these steps to install the NuGet package of ASP.NET MVC:

  1. Right-click on the dependencies, and select the Manage NuGet Packages option:

  1. We will see that a package called Microsoft.ASPNetCore.All is installed (as shown in the following screenshot). This package is actually a meta package that installs most of the dependencies we need.

  1. If we extend this package from dependencies, we will see:

So, everything we need is already installed regardless of using an empty project or not.

ASP.NET Core is installed in our application. Now, we need to tell our application to use ASP.NET MVC.

This needs a couple of changes to the Startup.cs file:

  1. Configure the application to add the MVC service. This can be done by adding the following line to the ConfigureServices method of the Startup class:

Go to https://goo.gl/RPXUaw to access the code.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
  1. Configure the routing so that our correct controllers will be picked for the incoming requests based on the URL entered. The following code snippet needs to be updated in the Configure method of the Startup.cs file:

Go to https://goo.gl/Xa1YcD to access the code.
public void Configure(IApplicationBuilder app,IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}
/{action=Index}/{id?}");
});
}

In the preceding statement, we are configuring the routes for our application.

In this chapter, and most of the chapters in this course, we will write codes manually or choose an Empty template instead of relying on scaffolding templates. For those who are new to the term scaffolding, scaffolding is a feature that generates all the necessary boilerplate code for you for the selected item (for example, the controller) instead of you needing to write everything.

Though scaffolding templates are useful and save time in generating the boilerplate code, they hide many of the details that beginners have to understand. Once you write code manually, you'll know all the intricacies of how each of the components is contributing to the big picture. Once you are strong in the fundamentals, you can use scaffolding templates to save you time in writing the boilerplate code. Scaffolding is also useful for creating quick administrative pages to edit our database.
主站蜘蛛池模板: 台州市| 温宿县| 临沂市| 大城县| 永济市| 阿图什市| 通江县| 偏关县| 赣榆县| 米泉市| 察雅县| 蓝山县| 连云港市| 内黄县| 山西省| 双牌县| 沁水县| 威远县| 大丰市| 昌黎县| 华坪县| 靖宇县| 永修县| 大埔区| 太和县| 安仁县| 垦利县| 北京市| 岳阳县| 临江市| 织金县| 舞钢市| 和硕县| 浮山县| 大邑县| 惠安县| 河源市| 东宁县| 昌宁县| 曲周县| 北海市|