We need to talk about Blazor

24 / 10 / 2021

Read Time 10 minutes

Blazor is a .NET based web application technology that allows you to build interactive applications leveraging C#, Razor, and HTML. The web app builder, Blazor, compiles to WebAssembly known as Wasm for short. This enables the new emerging technology to run in any modern web browser with great performance.

.NET in WebAssembly

WebAssembly is a binary instruction format for a stack-based virtual machine. Many languages like c#, Go and Rust can compile to Wasm meaning these languages can be used to develop within browsers. As a byte code format, there is no need for script parsing or pre-compile for optimization. The code is directly translated to native code improving performance at load and startup time compared to JavaScript. WebAssembly is not restricted to the JavaScript language because it implements its own instruction set. This means there is no need for JavaScript or Typescript.

The ability to compile the .NET Framework in Wasm gives us a whole new world of possibilities. Using Blazor we have the power of the .NET runtime and standard .NET libraries to our advantage within a browser, everything behaves exactly like .NET on the desktop or server.

Blazor VS … everything else

This new framework has much going for it with a lot of positive characteristics and piqued interest from the .NET community. It directly cuts the complexity of a multi-stack codebase, removing the need for third-party Frameworks like Angular, React and the millions of Javascript libraries that can be overwhelming, in complexity and learning, on our way to meeting requirements. With Blazor everything is unit-testable, strongly typed, conceptual modeling is easier and it comes in C#.

Server-Side vs Client-Side

Blazor comes in two main flavors, Server-Side and Client-Side. Server-side serves your single page application to the browser using Signal R. This approach gives us the full advantage of server-side execution, decreases initial download time and supports thin clients, meaning it will work on browsers that do not support web assembly or has resource constraints. The app and its components are not served to the client.

Personally, for me, the exciting part about Blazor is the ability to run the single page application client-side. The application is able to run independently on a clients device or browser with no dependency to the server. Because of the disadvantages associated with client-side architecture like downloading the .NET runtime including your application (compiled to Wasm) to the client, I would not recommend using this approach for general browser-based applications. However, the utilization of the Client-Side approach has just become very interesting from a mobile perspective.

Using both approaches we can share standard .NET libraries between two shell projects( server and client). We could develop a single login component or any other UI or backend component and reuse it in both server-side and client-side shell applications. Modularity is a great advantage when using Blazor.

Introducing BlazorMobile

As described on the GitHub page BlazorMobile – is a set of Nuget packages & project templates for embedding a Blazor web application as a standalone mobile application, hosted in Xamarin with native communication support.

The Client-Side shell compiles to a zip file and is then embedded within a Xamarin application at compile time. To use native functionality, a proxy interface can be added to a shared project between Blazor and Xamarin. The concrete implementation of the proxy interface is placed in a shared Xamarin project, available to the iOS, Android, UWP & Desktop shell projects. From the Blazor implementation the proxy interface is injected and called when required.

Final words

Blazor started as an experimental project by Microsoft software engineer Steve Sanderson and was quickly adopted into the .Net echo system, Blazor was officially released in .NET core 3.0. Sanderson says that Blazor is inspired by JavaScript frameworks such as React, Vue, and Angular but mashed up with technologies familiar to an ASP.NET programmer

I think a question on everyone’s minds is, will Blazor replace Frameworks like React, Vue, and Angular? In my opinion, this new exciting technology is definitely going to be a strong competitor with its ability to increase development speed and modularity. Building single-page applications with Blazor is surprisingly simple with a straight forward approach. There are no surprises or unexpected behavior, leaving us with a seamless development experience.

References

View
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website.

These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.

Necessary

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-Necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.