ASP.NET Core 3.0 - What's new? | 395 day | 587

ASP.Net Core 3.0 will be released at .NET Conf 2019 23-25 September 2019. In this post, I will show you what are the new features. 

1. New Project template

In order to use .NET Core 3 and ASP.NET Core 3 you need Visual Studio 2019. There are several project templates and sub-templates that are related to ASP.NET. Some of them are:

  • ASP.NET Core Web Application
  • Blazor App
  • gRPC Service
  • Razor Class Library

These project templates appear as top-level templates in New Project dialog.

Each of the top-level templates takes you to "sub-templates". For example, selecting ASP.NET Core Web Application template shows these options:

As you can see, the above figure displays the primary development options under ASP.NET Core - MVC, Razor Pages, and Web API. A few more templates can be found that use JS frameworks.

These project templates contain several improvements and changes. I encourage you to create a project based on each of these templates and take a peek into Program.cs, Startup.cs, and .csproj files.

2. New methods to register MVC / Razor Pages / Web API services

Prior to ASP.NET Core 3, you used methods such as AddMvc() inside ConfigureServices() to register certain services with DI container. The same method was used by MVC, Razor Pages, and Web API projects. In ASP.NET Core 3 there are three independent methods that do this job.

Take a look at this code fragment:

public void ConfigureServices
(IServiceCollection services)

You should use AddControllersWithViews() method in MVC applications. The Razor Pages and Web API applications should use AddRazorPages() and AddControllers() methods respectively. That means each of these methods is fine-tuned for a specific development option and registers only services related to that option. of course, you can call any combination of these methods depending on your needs. For example, if your app requires MVC and Web API then you will use AddControllersWithViews() and AddControllers() methods.

3. Endpoint routing

In previous versions of ASP.NET Core you used UseMvc() or UseMvcWithDefaultRoute() extension methods to wire routing middleware. Routing through these methods was the default option. A new form of routing called Endpoint Routing was introduced later but was not the default option. In ASP.NET Core 3 endpoint routing is the default way to deal with application routes. Older methods are still available but you should avoid using them because endpoint routing offers several advantages over traditional routing. This is how the endpoint routing looks like at code level:

app.UseEndpoints(endpoints =>
        name: "default",
        pattern: "{controller=Home}

4. Blazor server-side

Blazor has come a long way since its inception. From being an "experimental" feature it has become a full-fledged framework for building SPA kind of applications using C#, HTML, and CSS. That's right! You can build the goodness of SPA using Blazor without using JavaScript. Of course, it will take its own time to mature into a framework of choice but at least that process has begun. Blazor comes with two hosting models - server-side and client-side. The server-side hosting model uses SignalR as a channel for client-server communication. The client-side model uses WebAssembly download and run a .NET application in order to run it within the browser's boundary. As a part of the final release, Blazor server side is being released whereas Blazor client-side is planned to be released at some later date. Don't miss this welcome addition to the ASP.NET Core family.

The following figure shows Blazor server-side and client project templates.

5. gRPC support

As far as ASP.NET Core is concerned Web API became the prominent way to create services. Web API is a REST framework. gRPC is a framework for building services that are based on Remote Procedure Calls. It was originally developed by Google. and uses HTTP/2 for transport. gRPC project template is shown below:

6. JSON Serialization classes

JSON data format is quite common these days. In the previous versions, ASP.NET Core used Newtonsoft's Json.NET framework for its JSON processing. You can continue to use it in ASP.NET Core 3 also. However, there is a new set of classes that has taken over the responsibility. These classes reside inside System.Text.Json namespace and are used by default for all JSON processing in ASP.NET Core 3.

The JsonSerializer class has Serialize() and Deserialize() methods that can serialize .NET types to JSON and vice a versa. Async versions of these methods are also available.

7. Entity Framework Core 3 support

Entity Framework Core is a preferred way of writing data access logic under ASP.NET Core. EF Core 3 has a lot of additions and improvements as discussed here. Obviously, ASP.NET Core 3 can leverage all the feature improvements in EF Core 3. EF Core now also has Azure Cosmos DB provider that allows you to work with this emerging NoSQL database engine. 

8. New data provider for SQL Server - Microsoft.Data.SqlClient

Although EF Core has become quite popular due to its OR/M capabilities, there are cases when you need raw data access. If you ever worked with ADO.NET objects such as SqlConnection, SqlCommand, and SqlDataReader you know what I am referring to. Microsoft has developed a successor of System.Data.SqlClient that is available to .NET Core 3 applications as Microsoft.Data.SqlClient NuGet package. Although System.Data.SqlClient will be still available, going forward the new data provider is a recommended way to use in ASP.NET Core applications. If you are looking to quickly port existing ADO.NET code to ASP.NET Core 3 applications then Microsoft.Data.SqlClient would be of great help. Take a look into what it has to offer here.

9. Authentication and authorization middleware

In earlier versions of ASP.NET Core you used UseAutnentication() in the Configure() method to add authentication support and then used [Authorized] attribute in controllers and Razor Pages. Although this is still required, you also need UseAuthorization() to use [Authorize] attribute. There are other improvements to the authentication system such as support for certificate and Kerberos authentication. 

10. C# 8 support

.NET Core 3 supports C# 8 and you get all the additions and improvements outlined here. For examples, features such as default interface members, ranges, nullable reference types, asynchronous streams, and null-coalescing assignment can be used in your applications targeting .NET Core 3.

That's it for now! Keep coding!!

Top Articles

Bất Đầu Với WebApi Và Dot Net Core (.Net Core)

1276 day
Butter Ngo
Views 8930
Comments 0

Dot Net Core Bearer Token With (JWT) (.Net Core)

1208 day
Butter Ngo
Views 5557
Comments 0

Repository Và Unit Of Work (Entity Framework)

1195 day
Views 5038
Comments 0

Bắt Đầu Với Dot NET Core (.Net Core)

1287 day
Butter Ngo
Views 4424
Comments 0

Top Question

Bi lỗi Invalid Column Name khi sử dụng LinQ (.Net)

1135 day
Bảo Dương
Views 1337
Answers 2


428 day
Views 939
Answers 2

Làm thế nào để lấy information từ token (.Net Core)

525 day
Views 850
Answers 1