ASP.NET Core 2 brings a lot of improvements over 1.0 and 1.1, plus additional features. This video covers the .NET Core Runtime Store, the .ALL metapackage, the automatic Application Insights, and some of the minor incremental changes from 1.1.
- As you can see from the list, there are a lot of updates in ASP.NET Core 2.0. Updated features from 1.0 and 1.1, as well as plenty of new features. Grouped under package and runtime updates, there is now a meta package Microsoft.AspNetCore.All. That includes all of the ASP.NET Core Entity Framework their internal and third party dependencies in one package.
That is metapackage works with another new feature which is a .NET Core Runtime Store. And this contains all of the packages precompiled from the Asp.NetCore.All metapackage. So, when you deploy your application, depending on your deployment method, if you are doing a portable deploy, as we discussed in the earlier chapters, then the packages from the Asp.NetCore.All metapackage won't even be in your published package 'Cause it'll be coming straight from the .NET Core Runtime Store.
If you're doing a self contained install then they would be in the package. ASP.NET Core 2.0 also takes advantage of .NET Standard 2.0 which came out with .NET Core 2.0 and they can be referenced by any other.NET Standard 2.0 package. Now, it's important to point out that the metapackage only works with .NET Core 2.0 and not .NET Standard 2.0 because of its' use of the runtime store.
You might be wondering if I reference every single ASP.NET Core package and any framework package and all dependencies, that's a lot of packages I might not be using and there is a nice little package trimming feature. It's still on pre-release. That will then prune all those extra packages for you. So, I'm looking at the project file for the Spy Store 2.0 project, and you can see here, there are significantly less packages.
Now, Automapper is something that my code needs. It's not something that Asp.NetCore needs. The Kestrel.Https is still a separate package. That's not a standard place that you're going to put SSL. Usually, it's going to be done on either IIS or Apache or NGINX and then, the rest of what we have here are the tools. So, as we're going through all those features in 1.1 where we had to add additional packages, they are now included in the AspNetCore.All package.
From a trimming perspective, we add the Microsoft.Packaging.Tools.Trimming and you can see it's still on preview. And then, we do have to add in, in the property group by the target framework, a trim unused dependencies and set that to true. There are some minor updates from 1.1. Well, minor enough that they don't get their own section. Automatic precompilation of views is now on by default.
No additional packages or settings required. Of course, you can turn it off if you just set that value to false. Automatic use of anti-forgery tokens on form post actions. Now, this is the final step, I believe. In 1.0, when we used a form tag helper, then the anti-forgery token will be added for us. And now, in 2.0 on any of the form post actions, it's added for us.
Razor support has been added for C# 7.1 and we either set the language version to latest through the project file or through the property pages. And the final minor update that we're going to talk about in this little section is the environment tag helper, has now the include and exclude attributes in addition to the names attributes. So, if I go into the project property pages, build, advanced, I can then set the latest minor version, which will give us access to 7.1.
And if we open the layout file, under views, shared, layouts, and we look at the environment tag helper, we now have include and exclude. So, if we say include development, that is, include these files only if we are in the development environment and exclude is still including the files but we just want to exclude the development environment.
So, in 1.1 and 1.0, we had the names where we had a list of names where we wanted to include. That is still supported. This is just, in my opinion, a simpler way to make sure you're using the correct files in the environment. All of the starter templates have been update for 2.0. So that's whether you're doing it from the command line or Visual Studio. What you'll see in Visual Studio are new templates for Angular 4, React and React and Redux and then there's additional command-lines starter templates for Aurelia, Knockout and Vue.
A significant update that doesn't have really anything to show you in this class, is the automatic Application Insights. So, the restructure of the WebHostBuilder sets the stage for Application Insights to be added in to your project without having to recompile or redeploy. You can light up Application Insights in Visual Studio through the project context menu and you can also light it up for applications deployed in Azure with the Azure portal.
If you want to turn it on through Visual Studio, right click on your project, add, Application Insights Telemetry and for applications that are running in Azure, you'll be able to add them again without having to recompile or redeploy. Entity Framework Core continues to get better and better. 2.0 brought in again, as with every release, additional performance improvements. And there is now DbContext pooling available in AspNet.Core 2.0.
You have owned tables and table splitting. Like operator, improved LINQ translation. Global query filters, which are very powerful. String interpolation, which helps cut down on some of the security risks but could be a breaking change depending on how you quoted your 1.0 and 1.1 from SQL calls. Explicitly compiled queries and scalar function mapping, Plus, many, many more features. So, go check out the new EF features as well since you'll be most likely be using EF with your Asp.Net Core.
Let's look at the context pooling. And here, I have my start-up. And if we look, starting on line 47, we have services.AddDbContextPool, that's the only change we had to make. In 1.0 and 1.1, we just said, AddDbContext. Now, we say AddDbContextPool. Well, the really nice features of this, is that as a context gets returned to the pool, the change tracker is cleared.
So, you don't have to worry about cross user corruption of the change tracker within a DbContext. And the pooling helps performance because it is somewhat expensive to create a new DbContext. So, just like connection pools can make your application faster, the DbContextPool does that as well.
- Running and debugging ASP.NET Core applications
- Pros and cons of migrating existing applications to ASP.NET Core.
- Built-in dependency injection
- Environment awareness and app configuration
- Web host configuration and SSL
- View components invoked as tag helpers
- Configuration and logging
- Using Razor Pages