FOR MVC DEVLEOPERS THE FEAUTURES OF ASP.NET CORE
ASP.NET Core 1.0 gives a patched up Web development system adapted towards the prerequisites of present day Web applications. The new structure, as of now in RC1, obliges you to learn numerous new ideas not found in ASP.NET MVC 5. To that end, this article identifies a couple of essential components that ASP.NET MVC 5 designers ought to know as they get ready to take in this new structure.
1. ASP.NET Core on Numerous Runways
ASP.NET Core is a piece of .NET Core—another measured structure that backings numerous stages.ASP.NET and the .NET framework are focused on towards the Windows stage. Then again, ASP.NET Core is created to bolster various stages including Windows, Mac, and Linux. This additionally implies, dissimilar to ASP.NET web applications, basically, keep running under IIS, the ASP.NET Core applications can keep running under non-IIS Web servers. Figure 1 demonstrates the part of the .NET Core and ASP.NET Core.
The part of the .NET Core and ASP.NET Core -
A Web application worked with ASP.NET Core can target ASP.NET Framework 4.6 or the ASP.NET Core. The Web applications focusing on ASP.NET Framework 4.6 run just on the Windows stage. The Web applications focusing on the ASP.NET Core can keep running on Windows and non-Windows stages. Obviously, as on this composition, ASP.NET Core doesn't offer the same rich usefulness offered by ASP.NET Framework 4.6.
2. Part of Project.json
ASP.NET Core utilizes an exceptional document—Project.json for putting away all the undertaking level configuration data. Project.config can store numerous design settings, for example, references to NuGet bundles utilized as a part of the task and target structures.
The Project.json record stores configuration data in JSON position. The above markup demonstrates a conditions segment that contains a rundown of NuGet bundles required by the application. For instance, the Web application under thought requires the 6.0.0-rc1-last form of Microsoft.AspNet.Mvc get together, etc
3. Part of AppSettings.json
ASP.NET stores application configuration settings in Web.config. For instance, engineers utilize the <appSettings> area to store custom application settings, the <connectionStrings> segment to store database association strings, etc. ASP.NET Core utilizes AppSettings.json to store such bits of data.
Consider the accompanying configuration:
"Title": "My ASP.NET Core Application"
"ConnectionString": "data source=.;
initial catalog=Northwind;integrated security=true"
The previous JSON markup comprises of two properties or keys, to be specific AppSettings and Data. The AppSettings property holds a sub-key named Title. The Title sub-key has a string estimation of "My ASP.NET Core Application". Also, the Data key has a DefaultConnection sub-key. The DefaultConnection thusly has a ConnectionString sub-key.
4. Application set-up
In ASP.NET, Global.asax goes about as the passage point for your application. You can wire different events handlers for occasions, for example, Application_Start and Session_Start, in the Global.asax record. In ASP.NET Core, the application startup happens in an unexpected way—it happens through a Startup class.
one such Startup class -
public class Startup
public Startup(IHostingEnvironment env,
ConfigurationBuilder builder = new ConfigurationBuilder();
IConfigurationRoot config = builder.Build();
string str = config.Get<string>
// do something with str
public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app)
public static void Main(string args) =>
The Startup class appeared above starts with a constructor. The constructor stacks the AppSettings.json record utilizing ConfigurationBuilder class. The Get() strategy then is utilized to peruse the database association string put away in the AppSettings.json document.
The ConfigureServices() technique includes the administrations required by the application. For instance, here you add MVC and Entity Framework to the administrations gathering.
The Configure() technique determines and arranges the administrations included before for application's utilization. For instance, the MVC directing is designed in the code appeared previously.
5. Tag Helpers
In ASP.NET MVC 5, you utilized HTML assistants, for example, BeginForm(), LabelFor(), and TextBoxFor() to render structures and frame fields. You can keep on using HTML partners in ASP.NET Core, too. However, there is a superior option: Tag Helpers. Label aides take the type of standard HTML labels with certain extraordinary asp-* credits added to them.
Consider the accompanying markup that renders a structure:
<form asp-controller="Home" asp-action="Save" method="post">
<table border="1" cellpadding="10">
<td><label asp-for="FirstName">First Name :</label></td>
<td><input type="text" asp-for="FirstName" /></td>
<td><label asp-for="LastName">Last Name :</label></td>
<td><input type="text" asp-for="LastName" /></td>
<td><label asp-for="Email">Email :</label></td>
<td><input type="text" asp-for="Email" /></td>
<td><label asp-for="Phone">Phone :</label></td>
<td><input type="text" asp-for="Phone" /></td>
<input type="submit" value="Submit" />
Observe clearly, the properties that start with asp-. They are characterized by the label aides. For instance, the structure label aide utilizes asp-controller ascribe to indicate the objective controller name and asp-activity credit to determine the objective activity technique name. Correspondingly, asp-for traits utilized with name and info label partners tie a name or a text box to a model property. Label partners are more advantageous to use than HTML assistants in light of the fact that their linguistic structure nearly takes after the HTML markup.
6. View Components
In MVC 5, you utilized halfway perspectives as a way to reuse markup and code. ASP.NET Core presents View Components, the more intense and adaptable option. A perspective part comprises of a class normally acquired from ViewComponent base class and a perspective record containing the required markup. This programming model is entirely like the one utilized by controllers and perspectives. It permits you to separate code and markup from each other—code in the perspective segment class and markup in a perspective. Once made, you can utilize a perspective segment on a perspective by utilizing the @Component.Invoke() technique.
7. Dependency Injection
ASP.NET Core gives an inbuilt reliance infusion system. The DI system of ASP.NET Core offers four-lifetime modes for a sort being infused:
Singleton: An object of an administration (the sort to be infused) is made and supplied to all the requests to that administration. Along these lines, fundamentally all requests get the same article to work with.
Scoped: An object of an administration is made for every single request. In this way, every request gets another event of an administration to work with.
Transient: An object of an administration is made each time an article is asked.
Instance: For this situation, you are in charge of making an object of an administration. The DI system then uses that case in singleton mode said prior
public void ConfigureServices(IServiceCollection services)
Here, MyService is the sort to be enlisted with the DI structure and actualizes IMyService. The AddSingleton() technique enlists this type for Singleton mode portrayed previously. Once a sort is enrolled with the DI system, you can infuse it in a controller like this:
public class HomeController : Controller
private IMyService obj;
public HomeController(IMyService obj)
this.obj = obj;
8. Gulp, Grunt, and Bower Support
9. Single Programming for Web API Model for and MVC
In MVC 5, controllers acquire from the System.Web.Mvc.Controller base class. What's more, Web API 2 controllers acquire from System.Web.Http.ApiController. In ASP.NET Core, both of these structures are converged into a solitary system. Therefore, under ASP.NET Core, an MVC controller and Web API controller both acquire from Microsoft.AspNet.Mvc.Controller base class. You then can design viewpoints, for example, HTTP verb mapping and the directing of the controllers as coveted.
10. Static Files and the wwwroot Folder
Refer the figure following down -
After arrangement, the wwwroot turns into the Web application's root. Every one of the URLs to static records are determined as for this envelope. Along these lines,/pictures/logo.png anticipates that logo.png will be available under the wwwroot/pictures envelope.
ASP.NET Core 1.0 is a redone system outfitted towards present day cloud based, measured Web applications. Despite the fact that the new structure safeguards the key ideas of MVC 5, ASP.NET engineers will discover numerous contrasts between MVC 5 and ASP.NET Core 1.0. This article specified the imperative new components/ideas that you have to comprehend to start your voyage with ASP.NET Core 1.0.