Getting Started With ASP.Net 5: Part 1

In this section, we'll see the major changes for ASP.NET 5. The very first change is on the lines of the Project system. Projects are now based on the File System. So, all you need to do to add something to a project, say a new source code file, is to just place the file in the right directory. So, you can edit the source code file, save the file and build and that happens dynamically. Thanks to the new Roslyn compiler that compiles the source code in memory that allows for a faster build and faster refresh.

The project structure itself changed from previous versions. Also, one point to note when building applications is we now have two options for the runtime. The first is the full-blown runtime as 4.5.1 or greater than that and the second option is for a cloud-optimized runtime, also called the core CLR. Here, all the pieces, like the JIT Compiler and Garbage Collector are packaged and designed for high throughput and low memory consumption. And now the application can have this cloud-optimized environment embedded with the application that makes it easier to have a true side-by0side version and be embedded, in other words you can deploy the .NET Framework by copying the Nuget package. So, the idea behind this cloud version of the .NET runtime is, it should be platform-independent and that means it can also run on a Mac or LINUX machine.

Another great fact about the new changes in ASP.NET 5 is the unification. So, now:

MVC 6 = ASP.NET MVC + WEB API

In MVC 6, the Web API is merged with MVC. This means that we now have one set of controller classes, one set of attributes, model binders and so on. Also, it no longer relies on the namespace system.web which means it is easy to self-host and run the core CLR. Now, with these changes in place it doesn't mean that your existing projects won't work in Visual Studio 2015. They will work as smoothly as in earlier versions. Now, let's go ahead and start the demo. I already have the RC version of Visual Studio 2015 installed on my secondary machine. Let's go ahead and create a new project.



Now, the following window is very much similiar to the previous version. Here, I am interested in the new templates introduced. Hence, I will create a new project as an ASP.NET 5 Website. This project will provide me all the required components to run an app as shown below in the screenshot.



So, the following window will be the new window for the ASP.NET 5 project.



And when I run it, it will produce the following output. A very traditional MVC APP.





One point to also note is that now the folder organization in the file system and Solution Explorer is the same as you can see in the following screenshots.



This also means that whatever changes I make in the file system under the src folder will take effect in Visual Studio. Let's create a myImages folder in the file system with one image there. As soon as I added the image to the file system, it is automatically synced with the Solution Explorer.




Now, let's create one controller, say GreetController, but from Notepad. This is just to prove the point that we don't need to build the app for the code changes to take effect.



Now, after saving it, when I refresh the browser, it will return the new controller's output. So, this is called dynamic compilation.



Thanks for joining me for the first Edition of ASP.NET 5. We'll delve further in future topics. Until then stay tuned and Happy Coding.


Similar Articles