In this article we discuss about Introduction to Blazor. Blazor is a free, open source Web framework to build Web apps using C# that run in a Web browser. Blazor is a new .NET web framework for creating client-side applications using C#/Razor and HTML that runs in the browser with Webassembly. It can simplify the process of creating single page application (SPA) and at the same time enables full stack web development using .NET. For more details about blazor please follow Blazor Series.

How can a browser execute C# code?

Browsers understand and execute only JavaScript.

How can we execute c# code in the client browser. Well, the answer is WebAssembly.

Blazor can run C# code directly in the browser, using WebAssembly. It runs in the same security sandbox as JavaScript frameworks like Angular, React, Vue etc. Not just C# in fact we can run any type of code in the browser using WebAssembly.

WebAssembly is based on open web standards. It is a native part of all modern browsers including mobile browser. This means for the blazor application to work, there is no need to install any special plugin like back in the days of silver light and flash.

Introduction to Blazor

What is WebAssembly

  • WebAssembly developed as a web standard and support by all the major browsers without plugins.
  • It is a low-level assembly-like language with a compact binary format that can run in modern web browser.
  • WebAssembly a subset of JavaScript and designed to complement and run alongside JavaScript. It enables us to run code written in multiple language on the web at near native speed.

Why use Blazor ?

Blazor makes web development easier and more productive by touch with .NET. It runs in all browsers on the real .NET runtime and have full support for .NET Standard without the need of any extra plugin. Blazor is fast, have reusable components and is open-source with a great support from the community.
Blazor supports features of SPA framework , few are given below :

  • Routing
  • Layouts
  • Forms and validation
  • JavaScript interop
  • Server-side rendering
  • Dependency Injection

Blazor Hosting Models 

Hosting models are categorize into two parts.

  • Server Side
  • Client Side / WebAssembly

Server Side 

In Server side hosting model the application executed on the server from within an ASP.NET Core application. Between the client and the server, SignalR connection is established.

When an event occurs on the client such as a button click, for example the information about the event is sent to the server over the SignalR connection. The server handles the event and for the generated HTML a diff (difference) is calculated. The entire HTML does not sent back again to the client, this is only the diff that is sent to the client over the established SignalR connection. The browser then updates the UI.

Blazor embraces the single page application architecture which rewrites the same page dynamically in response to the user action. Since only the difference is applied to update the UI, the application feels faster and more responsive to the user.

We use the Blazor Server App template, to create a Blazor application with the server hosting model.

Client Side / Blazor WebAssembly

This is also called the client-side hosting model and the application runs directly in the browser on WebAssembly. So, everything the application needs i.e the compiled application code itself, it’s dependencies and the .NET runtime downloaded to the browser. We use the Blazor WebAssembly App template, to create a Blazor application with the client-side hosting model.

Conclusion

This article explain how to get and set connection string dynamically and access anywhere in the ASP.NET Core MVC application. Any suggestion for improvement about the article then please give your feedback.

Pin It on Pinterest

Share This