I thought to share my yet another experience with Entity Framework 7 where Lazy Loading is still not implemented. I was actually designing my Movie-Review API and soon after that I realized that results are unexpected, hence without wasting time, I directly checked with Microsoft. Here, is my conversation with Microsoft.
In this section, I am going to continue from the last section where I left the discussion. So, in this section, I am going to discuss more on authorization. In previous sections, we have already seen basic [Authorize] piece. Now, let us discuss some of the extended feature of the same.
In this section, I will continue from the last section and delve further into authentication. Now, let’s bring some OAuth capabilities into the application. So, the first change, I need to make here is to include the required packages in project.json file. Here, I will show another technique to add the required packages. We already know this technique and this is via Nuget Package Manager as shown below in the screen shot.
In this section, we are just going to focus on the authentication and authorization schemes around ASP.NET Core formerly known as ASP.NET 5. Ideally, authentication means, you got the right to enter like you got the ID card and swipe in office.
In today’s discussion, we’ll delve further to some more interesting features on ASP.NET 5. So, lets begin the show. Now, Let’s talk about the different CLR Types available with this project. So, when i talk about different CLRs; There are actually 2 versions of CLRs. 1st one is the usual one which has the full blown version of CLR which we have been using since it’s inception. Another one is the minimized version or also known as cloud optimized version of CLR. Now, let’s go ahead and check project settings.
As you can see in the above screen shot; my default setting is against full blown CLR which is running on the X86 machine. Now, if you see the drop down shown below. you will notice that i also have the option for cloud optimized version.
Now, let’s change the environment to cloud version and then run the app and inspect the output of the greet controller which we created in previous section. It should print my name there.
Now, let’s go ahead and debug this controller. So, now when i refresh the page it will hit the breakpoint as shown below.
Here, when I go in the modules section as shown below in the screen shot. It will list the complete flow. So, here you can see from where all the binaries loading. Basically modules are nothing but have one to one mapping with assemblies.But, you can also have multiple module per assembly. Now, this module window is showing me what all modules are loaded in the application.
Now, one point to note here that all these modules are coming from one location that is from user’s location as highlighted above. Let’s jump to this location for a minute and inspect the same.
Now, when I go inside there; i can see that there is nuget package file or NUPKG file which is around 14 MB.
This is complete Core CLR. Can you imagine. Now, what i can do is i can simply take this file and copy to different system my .NET Core version is ready. This bin directory here is the extracted version of this nuget package as shown in the below screen shot.
Also, when you go to the runtime folder and go to full blown CLR folder as shown below.
You will notice that size of the NUPKG file is very less compared to Core CLR version. Confused?
In case of full blown CLR, all components get loaded from GAC (Global Assembly Cache) not from here. But, it doesn’t mean that there is no centralized repository for Core CLR. So, if you go to below location; you will find packages folder.
So, now this will be the centralized repository for your Core CLR.
So, whenever, we install any dependencies it will sit here in this packages folder. So, ASP.NET 5 completely embraces nuget package. We manage dependencies via nuget package. We can have CLR stored through nuget package. Hence, these packages folder are referred as Global Package Cache.
Now, project.json is not only used to have the nuget dependencies only. we can have different project dependencies also listed here within the same solution. For example, let’s go ahead and add class library project to the solution folder. Make sure you install Vnext version of class library which means this class library project can have all the flexibilities of dynamic compilation what we have been using so far.
Once you added the project. Your solution will look like shown below. So, even the new project gets added under the src folder.
You will also notice that this new class library project also added new project.json file which also lists the dependencies accordingly for running Class library project.
Now, if i have to use this project in my web project; then i just need to include this newly created project in the dependencies section of project.json file of web project as shown below.
Now, when you don’t provide the version name against the package or project it will pull the latest one. Let’s go ahead and create some method in the class library project to return some meaningful thing.
Let’s use the same in Greet controller.
With this i will wrap this session. In the next section we’ll delve further into new features of ASP.NET 5. Till then stay tuned and Happy Coding.
In this section, we’ll delve further in the new ASP.NET 5 project. When you take a closer look at the ASP.NET 5 project, you will see that there are many things which are carry forwarded like Model, View, Controller, clean separation of concerns and may more. But, there are also some significant changes around ASP.NET 5. Now, the root of the website is no longer the root of the project. By default, root will be WWWroot folder. The idea behind this to maintain the clean separation between the files at the web-server retrieved and sent to the client and the files which contains the logic and configuration. Static files like JS, CSS, HTMLs can live in WWWroot folder.
Now, lets suppose when i run the app and tried to see the image which i have placed in My Imgaes folder, then it will give me 404 error.
On the other hand, if i go ahead and add the same folder in WWWroot folder and try to navigate the same then it will produce me the result.
so, the point is all static files are served by root folder and logical stuffs served by project space as we initially saw, when i added controller in the controller’s folder and it took effect. One more thing you might have observed that there is no web.config file now in the solution. Also now there is no Global.asax file; however the same is replaced by startup.cs file. But, we’ll see this later. 1st let’s see project.json file. This file now manages many aspects of website.
First thing which you will notice here that root folder is set to WWWroot here. So, this is the place which is telling website that this is the root folder. So begin the show from here. This you can change as well or rename if you like to. Now, this configuration file is in JSON format. This is also telling the ASP.NET runtime what dependencies project is going to need. In this new ASP.NET 5 system there is a new way to manage dependencies. No need to reference assemblies and store the lists of referenced assemblies in the project file. Instead we refer to nuget packages as dependencies and these dependencies are listed in our project.json file. Now, there are couple of reasons for this change. One reason is to simplify the dependency management. Another good reason for this is that ASP.NET is moving away from VS dependency. So, in future i can use any text editor to build the ASP.NET App.
Now, these dependencies can be both the ways. One way which we used already shown below in the screen shot.
Now, the UI of this also changed. Initially we used to have Modal window. Now, this is more like complete screen giving wider visibility. I can also see the installed templates like
Also, i still have the flexibility of different nuget source.
2nd Option is via project.json file. Let’s suppose i am planning to install some custom package. Then i can do like shown below as well
However, whatever package you install; you can find its references under “References“. Below, in the screen shot you can see that there are two versions of runtime here. 1st one is the core version and 2nd one is the cloud optimized version.
Now, let’s collapse the same and drill into it.
Now, here dependency management system will keep your assemblies in nice tree structure. So, it nicely tells which package are dependent on which package.
Now, as far as Framework and runtime is concerned as you can see below in the screen shot; i have both frameworks listed here.
So, whenever i am building the solution i am building against both of these frameworks. By building against both i am actually ensuring that it will work well against both the frameworks. This also means whenever i am switching platform my code won’t break there.
But, let’s go ahead and break something here. You remember in the last segment i created one new controller with a notepad. Now, let’s modify the same and refresh the app.
so, as you can see that it says that GetCallingAssembly() which is part of System.Reflection is not supported in the cloud optimized version. But, let’s suppose i overlooked this error and refresh the app.So, it actually produced me desired result.
But, when i explicitly build the project and checked the output window, then it gave me below error message.
so, building with error but application is working fine with full blown CLR. Now, if you have decided that you don’t want CORE CLR version. so, you can just comment the Core CLR section in the project.json file as shown below in the screen shot.
Now, as soon as i commented the above section, below references got refreshed automatically.
Now, when i build the app then it will build fine.
But, suppose you want the other way means you would like to keep the cloud optimized version also and build should also succeed. For this scenario i need to refer the conditional build as shown below.
With this i would like to wrap this 2nd session ASP.NET 5 New Features. We will delve further in the coming series. Till then stay tuned ad Happy Coding.
In this section, we’ll see that major changes on ASP.NET 5. The very 1st change is on the lines of Project system. Projects are now based on File System. So, all you need to do is add something to a project say new source code file is just to place the file in the right directory. So, you can edit the source code file, save the file and build just happens dynamically. Thanks to new Roslyn compiler which compiles the source code in memory which allows for faster build and faster refresh.
The project structure itself changed from previous versions. Also one point to note while building application, we’ll be having two different options of choosing runtime. 1st is the full blown runtime as 4.5.1 or greater than that or 2nd option we can have cloud optimized runtime also called core CLR. Here, all the pieces like JIT Compiler, Garbage Collector are packaged and designed keeping high throughput and low memory consumption in mind. And now the application can have this cloud optimized environment embedded with the application which makes it easier to have true side by side version and by embedded it means you can deploy the .net framework by copying the nuget package. So, the idea behind this cloud version of .NET runtime is; it should be platform independent which means it can also run on MAC and 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, WEB API is merged with MVC. This means we will now have one set of controller class, one set of attributes, model binders etc. 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 VS 2015; It will work as smooth as it was in earlier versions. Now, lets go ahead and start the demo. I already have RC version of VS 2015 installed on my 2ndry machine. Lets go ahead and create new project
now, the below window is very much familiar to previous version. Here, i am interested in the new templates introduced. Hence, i am going to create a new project with ASP.NET 5 Website. This project will give me all the required components to run an app as shown below in the screen shot.
so, below shown window will be the new window for ASP.NET 5 project.
And when i run the same, it will produce me the below output. Very traditional MVC APP.
One point to also note that now folder organization in the file system and solution explorer is same as you can see in the below screen shots.
This also means whatever changes i do in the file system under src folder it will take effect in VS. Let’s create myImages folder in the file system with one image there. As soon as i added the image in the file system, it gets automatically synced with Solution Explorer.
Now, lets create one controller say GreetController but from the notepad; this is just to prove the point that we don’t need to build the app to take the code changes effect.
Now, after saving the same when i refresh the browser, then it will return me new controller’s output. so, this is called dynamic compilation.
Thanks for joining me for the 1st Edition of ASP.NET 5. We’ll delve further in coming topics. Till then stay tuned and Happy Coding.
3,038 total views, 1 views today
Subscribe For Latest Updates!
Signup for My View newsletter and get notified when I publish new articles for free!