Introducing ASP.NET 5

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

The first preview release of ASP.NET 1.0 came out almost 15 years ago.  Since then millions of developers have used it to build and run great web applications, and over the years we have added and evolved many, many capabilities to it.  I’m excited today to post about a new release of ASP.NET that we are working on that we are calling ASP.NET 5.  This new release is one of the most significant architectural updates we’ve done to ASP.NET.  As part of this release we are making ASP.NET leaner, more modular, cross-platform, and cloud optimized.  The ASP.NET 5 preview is now available as a preview release, and you can start using it today by You enjoy a development experience that is similar to working with an interpreted language without sacrificing the benefits of a compiled language. You can also optionally use other code editors to work on your ASP.NET 5 projects. Every function within the Visual Studio user interface is matched with cross-platform command-line operations. Integration with Popular Web Development Tools (Bower, Grunt and Gulp) Another exciting feature in Visual Studio 2015 is built-in support for Bower, Grunt, and Gulp – popular open source tools that we think should be in every Web developer’s toolkit. Bower is a package manager for client-side libraries, including both JavaScript and CSS libraries. Grunt and Gulp are task runners, which help you to automate your web development workflow. You can use Grunt or Gulp for tasks like compiling LESS, CoffeeScript, or TypeScript files, running JSLint, or minifying JavaScript files.Bower: To add a JavaScript library to your ASP.NET project add it directly in the bower.json config file: Notice that Visual Studio gives you IntelliSense with a list of available packages. The next time you open the solution, Visual Studio automatically restores any missing packages, so you don’t need to check the packages into source control. For server-side packages, you’ll still use NuGet Package Manager. Grunt: In modern web development, you can find yourself managing a lot of tasks, just to build your app: Compiling LESS, TypeScript, or CoffeeScript files, linting, JavaScript minification, running JS unit tests, and so on. Every team will have its own set of requirements, depending on the particular tools that you use. Task runners make it easier to manage and coordinate these tasks. Visual Studio 2015 will support two popular task runners, Grunt and Gulp. For example, let’s say you want to use Grunt to compile LESS files. Just go into package.json and add the Use the new Task Runner Explorer in Visual Studio 2015 to bind the task to a build step (pre-build, post-build, clean, or when the solution is opened). This makes it incredibly easy to automate common tasks within your projects – and have them work both for you, as well as across a team wide project. Simplified dependency management In ASP.NET 5 you manage dependencies by adding NuGet packages. You can use the NuGet Package Manager or simply edit the JSON file (project.json) that lists the NuGet packages and versions used in your project. The project.json file is easy to work with and you can edit it with any text editor, which enables you to update dependencies even when the app has been deployed to the cloud. The project.json file looks like: In Visual Studio 2015, IntelliSense assists you with finding the available NuGet packages that you can add as dependencies. And, Intellisense can even help you with the available versions: Cloud-ready configuration In ASP.NET 5, we eliminated the need to use Web.config file for configuration values. We wanted to make it easier for you to deploy your app to the cloud and have the app automatically read the correct configuration values for that environment. The new system enables you to request named values from a variety of sources (such as JSON, XML, or environment variables). You can decide which formats work best in your situation. In the Startup.cs file, you can now add or remove the sources for configuration values. The above code snippet shows a project that is set up to retrieve configuration values from a JSON file and environmental variables. You can change this code if you need to specify other sources. In the specified config.json file, you could provide the values. In your host environment, such as Azure, you can set the environmental variables and those values are automatically used instead of local configuration values after the application is deployed. You can deploy your application without worrying about publishing test values. Dependency injection (DI) Dependency Injection (DI) is supported in existing ASP.NET frameworks, like MVC, Web API and SignalR, but not in a consistent and holistic way. ASP.NET 5 provides a built-in DI abstraction that is available in a consistent way throughout the entire web stack. You can access services at startup, in middleware, in filters, in controllers, in model binding and virtually any part of the pipeline where you want to use your services. ASP.NET 5 includes a minimalistic DI container to bootstrap the system, but you can easily replace the default container with your container of choice (Autofac, Ninject, etc). Services can be singleton, scoped to the request or transient. For example, to see how to use constructor injection with ASP.NET MVC 6, create a new ASP.NET 5 Starter Web project and add a simple time service: using System;   namespace WebApplication1 {     public class TimeService     {         public TimeService()         {             Ticks = DateTime.Now.Ticks.ToString();         }         public String Ticks { get; set; }     } } The simple service class sets the current Ticks when the constructor is called. Next, register the time service as a transient service in the ConfigureServices method of the Startup class: public void ConfigureServices(IServiceCollection services) {     services.AddMvc();     services.AddTransient(); } Then, update the HomeController to use constructor injection and to write the Ticks when the TimeService object was created. public class HomeController : Controller {     public TimeService TimeService { get; set; }       public HomeController(TimeService timeService)     {         TimeService = timeService;     }       public IActionResult About()     {         ViewBag.Message = TimeService.Ticks + ” From Controller”;         System.Threading.Thread.Sleep(1);         return View();     }       // Code removed for brevity } Notice the controller doesn’t create a TimeService. It’s injected when the controller is instantiated. In MVC 6 you can use the [Activate] attribute to inject services via properties. You can use [Activate] not just on controllers but also on filters, and view components. This means you can simplify your controller code like this: public class HomeController : Controller {     [Activate]     public TimeService TimeService { get; set; }       // Code removed for brevity } MVC 6 also supports DI into Razor views via the @inject keyword. In the code below, I’ve injected the time service into the about view directly and defined a TimeSvc property by which it can be accessed: @using WebApplication23 @inject TimeService TimeSvc   @ViewBag.Message       @TimeSvc.Ticks From Razor When you run the app, you can see different ticks values from the controller and the view. Fast HTTP performance ASP.NET 5 introduces a new HTTP request pipeline that is modular so you can add only the components that you need. The pipeline is also no longer dependent on System.Web. By reducing the overhead in the pipeline, your app can experience better throughput and a more tuned HTTP stack. The new pipeline is based on many of the learnings from the Katana project and also supports Docs and tutorials To get started with ASP.NET 5 you can find docs and tutorials on the ASP.NET site at http://asp.net/vnext. The following tutorials will guide you through the steps of creating your first ASP.NET 5 project. Manage Client-Side Web Development in Visual Studio 2015, Using Grunt and Bower View components and Inject in ASP.NET MVC 6Also read this article for even more ASP.NET and Web Development improvements coming this week. Hope this help, Scott

X ITM Cloud News

Ana

Next Post

New Azure Billing APIs Available

Mon Nov 25 , 2019
Spread the love          Organizations moving to the cloud can achieve significant cost savings.  But to achieve the maximum benefit you need to be able to accurately track your cloud spend in order to monitor and predict your costs. Enterprises need to be able to get detailed, granular consumption data and derive […]
X- ITM

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware

.

X ITM