In the second part of 2019, .NET Core in version 3.0 was released. One of the features for this version was the ability to create a client-side web application using Blazor. How does it work? How to create a project using Blazor? Is it likely to compete with JavaScript and its frameworks? I will try to answer these questions in this article. Let’s get started!

Flashbacks

When you read about features in the new version of .NET Core, didn’t you think it was ever there before? Microsoft has already tried to move the WPF application into the browser and created Silverlight. It was quite an interesting solution for those times, but it is definitely the past. Later, something like ASP.NET WebForms appeared. Main building blocks of pages there are server controls. In the case of this solution, applications were slow, mainly due to the transfer of very large amounts of data.

A more recent solution was ASP.NET MVC, which significantly accelerated the operation of the application, but also provided great freedom in creating views. They could be created in Razor, but also use JavaScript and its frameworks/libraries such as React or Angular.

Another try

However, Microsoft decided to try again and make that a fluent programmer in C# does not need to use other languages to create a web application. The perfect moment for this was the new technology, that is previously mentioned ASP.NET Core. It was then that the new framework, Blazor, was presented. Blazor is a mechanism that allows building web applications using C#, ASP.NET Core and Razor. There are two versions that can be distinguished in it: Blazor WebAssembly and Blazor Server.

Please leave this field empty Sign up for the newsletter to keep up to date with new articles!

Blazor Server

This version was realized in the second part of 2019. In short, the application is hosted on the ASP.NET Core server and the changes rendered by the client go back to the browser over the network and then sent back to the client using SignalR, as shown in the scheme below. SignalR is a library that allows real-time transfer content between the clients and the server.

source: docs.microsoft.com

Blazor WebAssembly

This part of Blazor will be realised in May 2020. It will make it unnecessary to render changes on the server. By using WebAssembly it becomes possible to use .NET on the browser side. This allows you to write the whole frontend in Razor without using JavaScript which will be maintained the client-side together with the entire code written in C#. This is illustrated in the diagram below:

source: docs.microsoft.com

First project using Blazor

First, you must have installed the latest version of .NET Core SDK and Visual Studio 2019. Then you can go on to create a new project:

After generating the project, you can go to the Startup.cs class and see the ConfigureServices method, where are added all the services required for creation views in Razor and for Blazor Server.

Now, look at one of the views to see how it is created. If you have ever had contact with Razor before, it won’t be anything new to you. Here you can see HTML with C# insertions, that’s how it looks in Razor:

That’s not all but keep calm

In addition to the Blazor editions mentioned above, Microsoft plans and works on other solutions such as Blazor PWA, Blazor Hybrid and Blazor Native. In short, it can be said that these solutions are for desktop and mobile applications. As you can see, Microsoft strives for the framework to be as universal as possible.

This all looks very promising, but can Blazor really cause .NET developers to stop using JavaScript? I don’t think so. It is certainly a forward-looking solution, but in my opinion, it will take some time when the system architects choose this solution in commercial projects.

Summary

In this article, I wanted to introduce you to Blazor and show you how technologies and solutions in web programming change. I think it’s worth following the development of this framework and learning about its capabilities. Maybe in some time the skill to write in Blazor will be desirable in the labour market?