for mvc developers the features of asp.net core

7
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.

Upload: sonia-merchant

Post on 23-Feb-2017

56 views

Category:

Education


4 download

TRANSCRIPT

Page 1: For mvc developers the features of asp.net core

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 newideas 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.

Page 2: For mvc developers the features of 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.

"dependencies": { "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final", "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final", "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "EntityFramework.Commands": "7.0.0-rc1-final", "Microsoft.AspNet.Session": "1.0.0-rc1-final", "Newtonsoft.Json": "8.0.3"

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 utilizethe <appSettings> area to store custom application settings, the <connectionStrings> segment tostore database association strings, etc. ASP.NET Core utilizes AppSettings.json to store such bits of data.

Consider the accompanying configuration:

{ "AppSettings": { "Title": "My ASP.NET Core Application" },

Page 3: For mvc developers the features of asp.net core

"Data": { "DefaultConnection": { "ConnectionString": "data source=.; initial catalog=Northwind;integrated security=true" } }}

The previous JSON markup comprises of two properties or keys, to be specific AppSettings andData. 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 theGlobal.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, IApplicationEnvironment app) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.SetBasePath(app.ApplicationBasePath); builder.AddJsonFile("appsettings.json"); IConfigurationRoot config = builder.Build(); string str = config.Get<string> ("Data:DefaultConnection:ConnectionString"); // do something with str } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddEntityFramework() .AddSqlServer(); } public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); app.UseMvc(routes =>

Page 4: For mvc developers the features of asp.net core

{ routes.MapRoute( name: "default", template: "{controller=Home}/ {action=Index}/{id?}"); }); } public static void Main(string[] args) => WebApplication.Run<Startup>(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. Forinstance, 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(), andTextBoxFor() 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"> <tr> <td><label asp-for="FirstName">First Name :</label></td> <td><input type="text" asp-for="FirstName" /></td> </tr> <tr> <td><label asp-for="LastName">Last Name :</label></td> <td><input type="text" asp-for="LastName" /></td> </tr> <tr> <td><label asp-for="Email">Email :</label></td> <td><input type="text" asp-for="Email" /></td>

Page 5: For mvc developers the features of asp.net core

</tr> <tr> <td><label asp-for="Phone">Phone :</label></td> <td><input type="text" asp-for="Phone" /></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Submit" /> </td> </tr> </table></form>

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 utilizedby 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 articleto 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)

Page 6: For mvc developers the features of asp.net core

{ services.AddMvc(); services.AddSingleton<IMyService,MyService>();}

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 sortis 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

Gulp and Grunt are JavaScript assignment runners. They help you computerize generally required undertakings, for example, packaging JavaScript and CSS records, minifying JavaScript and CSS documents, and arranging Less and Sass records (and some more). They areintroduced utilizing npm (Node Package Manager). The ASP.NET Core venture made utilizing Visual Studio 2015 permits you to include Grunt and Gulp arrangement documents furthermore gives Task Runner Explorer to screen the errands.

Bower is a bundle administrator basically for front-end bundles. Front-end bundles are the bundles that you use in your Web pages, for example, JavaScript libraries/systems and CSS records. For instance, you may introduce jQuery in your ASP.NET Core venture by utilizing Bower. An ASP.NET Core venture made utilizing Visual Studio 2015 permits you to include a Bower setup document. You likewise can work with the bundles utilizing the Manage Bower Packages menu choice.

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 ofthese 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

Page 7: For mvc developers the features of asp.net core

In ASP.NET, there is no settled area for putting away static documents, for example, picture records, JavaScript documents, and CSS records (engineers regularly utilized a Content envelope to store such documents). In ASP.NET Core, all the static records are kept under the wwwroot envelope (default). You likewise can change the name of this envelope by utilizing theProject.json document.

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.

Conclusion -

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.

We the institute provide training in dot net field to freshers to know the reviews about our company visit crb tech reviews.

Related Articles:

8 Killer Techniques To Learn .NET

Top 5 Reasons That Make ASP.NET More Secure Over PHP