Browser + Razor = Blazor!

Haven’t heard of WebAssemblies yet? Check some other articles to shortly educate yourself about WebAssemblies before continue reading.

Ok, but what about C#? As far as my research did take place, there is currently Mono and Microsoft working on a project (Experimental). Since the Mono Project on GitHub lacks too much guidance and I haven’t the power of will to read through their code, we will just skip their experimental project in this article. (Side note: Blazor runs on Mono)

Lets get into it! The repro of the Blazor project can be found on GitHub.

Installation (Essentials)

  1. .NET Core 2.1 SDK
  2. Visual Studio 2017
  3. Blazor Language Extension
  4. Compatible Browser

Project Creation

File -> New -> Project -> ASP.NET Core Web Application

ASP.NET Core Web Application

Select Blazor as a project template. If there is no Blazor template, you are missing the Blazor Language Extension, mentioned above. The Blazor template does not require a server running an IIS. The hosted one (ASP.NET Core hosted) does, but provides the advantage of a .NET server backend as well.

Blazor Template Selection

And we are ready to go. Select the browser of your choice and start the application.

Runnig instance of Blazor

What just happend?

We are running a .NET Application directly in the browser! Lets have a quick peek at the developer console.

Developer Console: Network output

The browser (in my case: Edge) did receive a mono.wasm file, which is a WebAssembly and includes a .NET runtime environment. Thus, we can simply send .dll files to the browser and the Mono-Runtime is able to execute the code. (Like the .dlls, also visible in the screenshot above)

I uploaded the binaries + the index.html to my Web-Server. Feel free to visit the WebAssembly: https://www.indie-dev.at/Blazor/Example/ Remember, there is no IIS running on the server! What you see is already running on your client. However, if you want/need a .NET server backend as well, use the Blazor (ASP.NET Core Hosted) template.

Great, but what’s next?

The mono.wasm (.NET WebAssembly Runtime) is currently restricted to .NET Standard 2.0. Thus, what can be done is extremely limited. But what is Blazor currently aware of?

  • A component model for building composable UI
  • Routing
  • Layouts
  • Forms and validation
  • Dependency injection
  • JavaScript interop

And what Blazor will support

  • Live reloading in the browser during development
    Server-side rendering
  • Full .NET debugging both in browsers and in the IDE
    Rich IntelliSense and tooling
  • Ability to run on older (non-WebAssembly) browsers via asm.js
  • Publishing and app size trimming

Conclusion

Since this project is still in development and currently flagged as “experimental” we can’t expect too much. With that said, I still would like to sum a few things up to address the boundaries.

  • Debugging is not supported
  • Arbitrary Exceptions after compilation
  • Intellisense nearly none-existing
  • Threading seems to break the application (InFinite Loop)
  • Tasks also seem to break the application (InFinite Loop)
  • .NET Standard 2.0 (Few NuGet packages)

For me, Blazor is currently a small playground. Maybe in a few years we are able to build our first enterprise applications with it. But for now, it stays an experimental prototype as a proof of concept.

Blazor API: https://blazor.net/api/index.html

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.