Oleksandr Skachkov, Itera
Running C# in your Web Browser with
WebAssembly
ABOUT ME
• Itera’s FrontEnd Tech Lead
• WebKit contributor
• WebAssembly enthusiast
• Twitter: @alSkachkov
• JavaScript in the Web
• WebAssembly’s key features
• WebAssembly and C#
• Blazor
JavaScript has monopoly in the Web
C# developer asked to do some JavaScript
New solution!
Blazor on WebAssembly
• Announced in 17 June 2015
• Supported by major Browsers
• Developed by WebAssembly Working
Group (W3C)
• Draft specific published 15 Feb 2018
WebAssembly – New Hope
What is WebAssembly (aka WASM)?
safe, portable, low-level code format designed for efficient execution
and compact representation
https://webassembly.github.io/spec/intro
C - Source code
RUST - Source code
S - Expression
fast to load
Byte code
WebAssembly’s key features
quick validation (parsing)
S-expression
S-expression
$0 10
Stack
S-expression
$0
10
10 * $0
Stack
S-expression
10 * $0
Stack
S-expression
Streaming API
1
3 2 1
5 4 3 2 1
No garbage collector
Only 4 primitive types
No access to DOM and WEB API
INTERACTION WITH JAVASCRIPT
We can use JS function in WASM and WASM function in JS
WEBASSEMBLY WILL BRING TO WEB
• High performance
• New languages
• Variety of existed libraries
WebAssembly and C#
.NET RUNTIME
• Mono
• https://github.com/mono/mono
• https://github.com/lrz/mono-wasm
• CoreRT
• https://github.com/dotnet/corert
• https://github.com/dotnet/llilc
WEBASSMBLY .NET FRAMEWORKS
• Blazor - https://github.com/aspnet/Blazor
• Xamarin.FORMS - https://github.com/praeclarum/Ooui
• NoesisGUI - http://www.noesisengine.com
BLAZOR. KEY FEATURES
• Built specially for SPA
• Use C# in Browser!
• Own shadow DOM
• Same codebase for both ENDS
BLAZOR
• Blazor concept announced at NDC Jul 10 2017
• Bring C# to the WEB
• Blazor = Browser + Razor
• At start relied on DotNetAnywere
• Currently relies on Mono WebAssembly
• Current version 0.1.0
• Not a new Silverlight!
CLR IN BROWSER
HOW BLAZOR WORKS
BLAZOR. FEATURES
Components
Routing
Binding
Dependency injection
HTTP Calls
JavaScript interop
Support asm.js for old browsers
COMPONENTS
• C# class from .cshtml
• Master page
• Reusable components
• Shadow DOM and diff base update
• Can be created fully in C#
• Life cycle methods/event, ie onInit …
COMPONENT
ROUTING
BINDING
BINDING
BINDING
BINDING
DEPENDENCY INJECTION
HTTP CALLS
JAVASCRIPT INTEROP: JS FROM C#
JAVASCRIPT INTEROP: C# FROM JS
JAVASCRIPT INTEROP: C# FROM JS
SOME MORE
REDUX: https://github.com/torhovland/blazor-redux
Entity Framework: https://www.c-sharpcorner.com/article/asp-net-core-crud-
using-blazor-and-entity-framework-core/
BLAZOR. HOW TO START
https://blogs.msdn.microsoft.com/webdev/2018/03/22/get-started-building-
net-web-apps-in-the-browser-with-blazor/
https://learn-blazor.com/
SUMMARY
• WebAssembly is an emerging technology
• Blazor on earliest stages
• Blazor very promising Framework
• Large build package for the Web
RESOURCES
• Blazor: https://learn-blazor.com
• Blazor github: https://github.com/aspnet/Blazor
• Blazor gitter: aspnet/Blazor
• Steven Sanderson: http://blog.stevensanderson.com
• WebAssembly Site: http://webassembly.org/
• Github: https://github.com/WebAssembly/
THANKS!
QUESTIONS?

Oleksandr Skachkov "Running С# in your Web Browser with WebAssembly"

Editor's Notes

  • #5 Stackoverflow.com Github.com
  • #7 Stackoverflow.com
  • #8 Stackoverflow.com