Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Blazor WebAssembly by Example
Blazor WebAssembly by Example

Blazor WebAssembly by Example: A project-based guide to building web apps with .NET, Blazor WebAssembly, and C#

Arrow left icon
Profile Icon Toi B. Wright
Arrow right icon
Can$12.99 Can$44.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (12 Ratings)
eBook Jul 2021 266 pages 1st Edition
eBook
Can$12.99 Can$44.99
Paperback
Can$55.99
Subscription
Free Trial
Arrow left icon
Profile Icon Toi B. Wright
Arrow right icon
Can$12.99 Can$44.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (12 Ratings)
eBook Jul 2021 266 pages 1st Edition
eBook
Can$12.99 Can$44.99
Paperback
Can$55.99
Subscription
Free Trial
eBook
Can$12.99 Can$44.99
Paperback
Can$55.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Blazor WebAssembly by Example

Chapter 1: Introduction to Blazor WebAssembly

Blazor WebAssembly is Microsoft's new single-page application (SPA) framework for building web applications on .NET Framework. It enables developers to run C# code on the client. Therefore, instead of being forced to use JavaScript on the browser, we can now use C# on the browser.

In this chapter, we will prepare you to develop web applications using Blazor WebAssembly. We will discuss the two different Blazor hosting models and present the advantages of using Blazor WebAssembly over Blazor Server. Finally, we will guide you through the process of setting up your computer to complete the projects in this book.

In this chapter, we will cover the following topics:

  • Benefits of using the Blazor framework
  • Differences between the two hosting models
  • What is WebAssembly?
  • Setting up your PC

Benefits of using the Blazor framework

Using the Blazor framework has several benefits. For starters, it is a free and open source framework built on Microsoft's robust .NET Framework. Also, it is an SPA framework that uses Razor syntax and can be developed using Microsoft's exceptional tooling.

.NET Framework

Blazor is built on .NET Framework. Since Blazor is built on .NET Framework, anyone familiar with .NET Framework can quickly become productive using the Blazor framework. The Blazor framework leverages the robust ecosystem of .NET libraries and NuGet packages from .NET Framework. Also, since both client and server code are written in C#, they can share code and libraries, such as the application logic used for data validation.

Blazor is open source. Since Blazor is a feature of the ASP.NET framework, all of the source code for Blazor is available on GitHub as part of the dotnet/aspnetcore repository that is owned by the .NET Foundation. .NET Foundation is an...

Hosting models

Blazor has two different hosting models. The first hosting model that Microsoft released is the Blazor Server model. In this hosting model, the web app is executed on the server. The second hosting model that Microsoft released, and the topic of this book, is the Blazor WebAssembly model. In this hosting model, the web app is executed on the browser.

Each hosting model has its own advantages and disadvantages. However, they both use the same underlying architecture. Therefore, it is possible to write and test your code independent of the hosting model. The major differences between the two hosting models concern latency, security, data access, and offline support.

Blazor Server

As we just mentioned, the Blazor Server hosting model was the first hosting model released by Microsoft. It was released as part of the .NET Core 3 release in September 2019.

The following diagram illustrates the Blazor Server hosting model:

Figure 1.1 –...

What is WebAssembly?

WebAssembly is a binary instruction format that allows code written in C# to run on the browser at near-native speed. To run .NET binaries in a web browser, it uses a version of the .NET runtime that has been compiled to WebAssembly. You can think of it as executing natively compiled code in a browser.

WebAssembly is an open standard developed by a W3C Community Group. It was originally announced in 2015, and the first browser that supported it was released in 2017.

WebAssembly goals

When WebAssembly was originally being developed, there were four main design goals for the project:

  • Fast and efficient
  • Safe
  • Open
  • Don't break the web

WebAssembly is fast and efficient. It is designed to allow developers to write code in any language that can then be compiled to run in the browser. Since the code is compiled, it is fast and performs at near-native speed.

WebAssembly is safe. It does not allow direct interaction with the browser...

Setting up your PC

For the projects in this book, we use Visual Studio 2019, .NET 5.0, and SQL Server 2019.

All of the projects are built using Visual Studio 2019 Community Edition version 16.9.5 with the ASP.NET and Web Development workload. If you need to install Visual Studio 2019, follow the directions in the Installing Visual Studio Community Edition section later in this chapter.

Tip

Although we are using Visual Studio 2019 Community Edition, any edition of Visual Studio 2019 can be used to complete the projects in this book. Microsoft Visual Studio Code can also be used.

Blazor WebAssembly in .NET 5 requires .NET 5.0. To check the version of .NET that is running on your computer, open the Command Prompt and enter the following command:

dotnet –-version

If your computer is not running .NET 5.0, follow the directions in the Installing .NET 5.0 section later in this chapter.

The final two projects in this book use SQL Server 2019 Express Edition as...

Summary

After completing this chapter, you should understand the benefits of using Blazor WebAssembly versus other web development frameworks and be prepared to complete the projects in this book.

In this chapter, we introduced the Blazor framework. The Blazor framework is built on .NET Framework and allows developers to use C# on both the frontend and backend of a web app.

After that, we compared Blazor Server with Blazor WebAssembly. Blazor WebAssembly has many advantages over Blazor Server due to the fact that it runs on the browser while Blazor Server runs on the server. A Blazor WebAssembly web app can run offline and feels much more like a native application because all of the code is run directly on the browser. Finally, a Blazor WebAssembly app can be easily converted into a PWA.

In the last part of the chapter, we explained how to set up your computer with Visual Studio 2019 Community Edition, .NET 5.0, and SQL Server 2019 Express, all of which are required to complete...

Questions

The following questions are provided for your consideration:

  1. Does using Blazor WebAssembly mean that you never need to write JavaScript ever again?
  2. Does Blazor WebAssembly require that any plugins be installed on the browser?
  3. How much does it cost to get started developing with Blazor WebAssembly?

Further reading

The following resources provide more information concerning the topics in this chapter:

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore complete, easy-to-follow web projects using Blazor
  • Build projects such as a weather app, expense tracker, and Kanban board with real-world applications
  • Understand and work with Blazor WebAssembly effectively without spending too much time focusing on the theory

Description

Blazor WebAssembly makes it possible to run C# code on the browser instead of having to use JavaScript, and does not rely on plugins or add-ons. The only technical requirement for using Blazor WebAssembly is a browser that supports WebAssembly, which, as of today, all modern browsers do. Blazor WebAssembly by Example is a project-based guide for learning how to build single-page web applications using the Blazor WebAssembly framework. This book emphasizes the practical over the theoretical by providing detailed step-by-step instructions for each project. You'll start by building simple standalone web applications and progress to developing more advanced hosted web applications with SQL Server backends. Each project covers a different aspect of the Blazor WebAssembly ecosystem, such as Razor components, JavaScript interop, event handling, application state, and dependency injection. The book is designed in such a way that you can complete the projects in any order. By the end of this book, you will have experience building a wide variety of single-page web applications with .NET, Blazor WebAssembly, and C#.

Who is this book for?

This book is for .NET web developers who are tired of constantly learning new JavaScript frameworks and wish to write web applications using Blazor WebAssembly, leveraging the power of .NET and C#. The book assumes beginner-level knowledge of the C# language, .NET framework, Microsoft Visual Studio, and web development concepts.

What you will learn

  • Discover the power of the C# language for both server-side and client-side web development
  • Use the Blazor WebAssembly App project template to build your first Blazor WebAssembly application
  • Use templated components and the Razor class library to build and share a modal dialog box
  • Understand how to use JavaScript with Blazor WebAssembly
  • Build a progressive web app (PWA) to enable native app-like performance and speed
  • Understand dependency injection (DI) in .NET to build a shopping cart app
  • Get to grips with .NET Web APIs by building a task manager app

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 09, 2021
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781800563933
Vendor :
Microsoft
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 09, 2021
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781800563933
Vendor :
Microsoft
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 221.97
Web Development with Blazor
Can$63.99
Blazor WebAssembly by Example
Can$55.99
C# 10 and .NET 6 – Modern Cross-Platform Development
Can$101.99
Total Can$ 221.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Chapter 1: Introduction to Blazor WebAssembly Chevron down icon Chevron up icon
Chapter 2: Building Your First Blazor WebAssembly Application Chevron down icon Chevron up icon
Chapter 3: Building a Modal Dialog Using Templated Components Chevron down icon Chevron up icon
Chapter 4: Building a Local Storage Service Using JavaScript Interoperability (JS Interop) Chevron down icon Chevron up icon
Chapter 5: Building a Weather App as a Progressive Web App (PWA) Chevron down icon Chevron up icon
Chapter 6: Building a Shopping Cart Using Application State Chevron down icon Chevron up icon
Chapter 7: Building a Kanban Board Using Events Chevron down icon Chevron up icon
Chapter 8: Building a Task Manager Using ASP.NET Web API Chevron down icon Chevron up icon
Chapter 9: Building an Expense Tracker Using the EditForm Component Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(12 Ratings)
5 star 66.7%
4 star 16.7%
3 star 16.7%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Jul 14, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Packt never fails to impress with their content. Blazor WASM is an awesome new tool and this teaches you everything you need to know to make a well designed application. Like all Packt books, it is easy to pick up in different chapters depending on what you want to learn. I was specifically looking more into how to make a PWA with Blazor and this was a fantastic guide!
Amazon Verified review Amazon
Paul Schroeder Jul 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I appreciate the author’s “no fluff” approach to covering all the basics Blazor developers need to know. As someone who has developed a few Blazor applications already, this meant that I was able to finish the content in just a few sessions. Being somewhat experienced, I certainly did pick up some new information, but I think beginner-to-intermediate developers will get the most out of this book.Personally, I thought the use of project templates was very appropriate and I wish more Visual Studio developers made use of this gem of an IDE feature. The sections on RenderFragment, EventCallback, CSS isolation, attribute splatting, and JS Interop were explained nicely. Content on Progressive Web Apps contained details, like the service worker life cycle, that were good to learn more about.I was impressed at the author’s ability to present straightforward examples, each of which demonstrated a Blazor capability with minimal code. Sticking close to just what is needed made it easy to understand what was happening.Overall, I liked this book, which is clearly designed to be a quick overview of each topic. After covering the basics, the author provides “further reading” sections at the conclusion of each chapter to make it easy to go deeper, if desired. There are also sample questions along the way that help you gauge your knowledge or think about what could be next if you want to experiment with extending the project samples.
Amazon Verified review Amazon
Adam Smith Apr 10, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book has a very pleasant way of teaching. A kind of step-by-step way. I give it a full 5 stars.
Amazon Verified review Amazon
Daniel Correa Aug 08, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Blazor WebAssembly is the Microsoft's single-page application (SPA) framework for building web applications on .NET Framework. It is another option that front-end developers should have in mind. One of the main difference with their main competitors (Vue, React, Angular) is that it enables developers to run C# code on the client. It means, you can develop an entire SPA application without using JavaScript.Toi (the author of this book) teaches us how to use Blazor WebAssembly in a practical way. She provides a set of projects and examples which are very useful and which teaches us the fundamental elements of Blazor WebAssembly. For example, (i) you will implement a simple modal dialog application, which focuses on razor elements, components, and RenderFragments. (ii) You will implement a simple data storage application, which explains how to use JS Interop to execute some JavaScript commands from a Blazor WebAssembly application (there are some cases in which using JavaScript makes sense). (iii) You will implement a Weather App which uses service workers, APIs, and implementation of PWA applications. And (iv) even, it takes you to develop a complete front-end and back-end application (task manager) with the use of an ASP.NET Web API. Other topics and projects include: application state, events, edit forms, and dependency injection.All those projects (and many others) present proper explanations, with excellent examples. The code of the projects is easy to follow, simple, and properly detailed. Therefore, you can use some of those projects as a base to develop your own applications.This is a totally recommended book if you want to learn Blazor WebAssembly in a practical way, with very useful examples, and short explanations. Congratulations to the author.
Amazon Verified review Amazon
Justin Horner Jul 15, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love reading through example-focused books, and Blazor by Example is no exception! As the title states, this is a project-based guide to building web apps with .NET, Blazor WebAssembly, and C#.On your journey through learning Blazor by Example, you'll create several applications that scale up in complexity by chapter. Everything from creating your first Blazor application and making a weather app PWA to handling application state in a shopping cart experience gets covered throughout the projects in the book.I highly recommend this book to anyone interested in Blazor. It's a great learning resource and reference for Blazor WebAssembly projects.Here are a few of my chapter/topic highlights:- JS Interop- Building a Progressive Web App (PWA)- Using Application State- Building a Kanban Board using Events- Building a Task Manager using ASP.NET Web API
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.