Professional Documents
Culture Documents
Full Chapter Blazor Webassembly by Example Second Edition PDF
Full Chapter Blazor Webassembly by Example Second Edition PDF
Full Chapter Blazor Webassembly by Example Second Edition PDF
Second Edition --
Visit to download the full and correct content document:
https://textbookfull.com/product/blazor-webassembly-by-example-second-edition/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://textbookfull.com/product/code-for-opencv-3-x-with-python-
by-example-second-edition-gabriel-garrido/
https://textbookfull.com/product/javafx-9-by-example-dea/
https://textbookfull.com/product/azure-data-factory-by-example-
practical-implementation-for-data-engineers-second-edition-
richard-swinbank/
https://textbookfull.com/product/unity-2018-by-example-learn-
about-game-and-virtual-reality-development-by-creating-five-
engaging-projects-second-edition-alan-thorn/
Plasma Simulations by Example 1st Edition Lubos Brieda
https://textbookfull.com/product/plasma-simulations-by-
example-1st-edition-lubos-brieda/
https://textbookfull.com/product/neurotrauma-neurosurgery-by-
example-christopher-j-madden/
https://textbookfull.com/product/pediatric-neurosurgery-
neurosurgery-by-example-nathan-selden/
https://textbookfull.com/product/javaserver-faces-introduction-
by-example-juneau-josh/
https://textbookfull.com/product/ibm-spss-by-example-a-practical-
guide-to-statistical-data-analysis-second-edition-service-des-
societes-secretes/
Blazor WebAssembly By
Example
Second Edition
Toi B. Wright
BIRMINGHAM—MUMBAI
Blazor WebAssembly By Example
Second Edition
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in
any form or by any means, without the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any
damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee
the accuracy of this information.
ISBN 978-1-80324-185-2
www.packt.com
To my boys, for their never-ending patience and understanding. To my readers, for their ceaseless curiosity
about new technologies.
– Toi B. Wright
Foreword
Hi, friends! I love a good second edition. It’s an opportunity to update and add to something that’s
already great. You take feedback from the readers and the community, absorb the zeitgeist, and
turn an A into an A+. Toi has taken Blazor WebAssembly By Example to the next level and now
we welcome you all, readers old and new.
I have known Toi Wright for more than 17 years. I first met her at the Microsoft MVP Summit in
Redmond back in 2005, if you can believe that. She is a brilliant technologist, community leader,
and tech organizer, and we see each other every year at the annual Microsoft MVP Summit. I’ve
had the opportunity to travel from my home in Portland to beautiful Dallas to speak in person at
the Dallas ASP.NET User Group where she’s the president and founder.
Toi has been very active in the ASP.NET community for many years. She brings energy and exper-
tise to everything she does. She has written courseware for Microsoft on ASP.NET and this is her
third book on the topic. She’s a respected programmer, architect, and communicator.
In this book, she walks you step by step through the creation of 11 standalone projects that are
built using the Blazor WebAssembly framework. You’ll learn how to leverage your experience
with the .NET ecosystem to complete many different types of projects. Blazor takes .NET – and
your .NET skills – to the web in a new way, and this book is the key.
The second edition adds small updates everywhere, but also includes new chapters on debugging,
deploying to Azure, and using tech like Azure Active Directory to secure a Blazor WebAssembly app.
In Blazor WebAssembly By Example, Toi shares her extensive knowledge and years of experience
as a web developer and has created an easy-to-follow guide for you to quickly learn how to use the
Blazor WebAssembly framework. Through her words, step-by-step instructions, copious screenshots,
and code samples, you will get started running C# in your browser instead of JavaScript. Everything
she’ll show you, including .NET and Blazor itself, is all open source and based on open standards! I’m
so glad that we both have a partner in Toi Wright to guide us in this powerful new web framework!
Toi B. Wright currently works with an amazing team at First Command Financial Services, Inc.
In 2020 he founded Ellycode to combine two great passions of his life, artificial intelligence and
user experience, which led to the creation of a dashboarding and data visualization platform: Elly.
Last but not least, his passion for teaching prompted Michele to found Improove; a startup that
will redefine the concept of teaching online courses.
He has always believed in the value of sharing, which is why, in December 2008, he founded
DotNetCampania, a Microsoft community for which he has organized many free regional confer-
ences. Microsoft awarded him the MVP award for these activities. In 2020, he brought his passion
to Blazor Developer Italiani, the Italian community on the Blazor framework, of which he is the
founder and community manager. His love for digital pushed him, again in 2020, to join Fare
Digitale, an association that promotes the enhancement of digital culture in Italy.
Michele also speaks at the most important Italian and international conferences on Microsoft
and JavaScript technologies. He has written several technical books and defines himself as a
community addict.
Vincent Baaij has been working as a developer/consultant/architect in the IT industry for over
25 years and is still learning new things every day. His focus has always been on the Microsoft and
.NET stack. Since 1999, he has worked primarily with content management systems like Umbraco
and Episerver (now Optimizely). The open-source tools he created when he was an Episerver
employee are ranked among the most popular community-contributed packages.
At present, Vincent works as a Cloud Solution Architect at Microsoft where he helps customers to
be successful on the Azure platform. He is also the maintainer of the official Microsoft Fluent UI
Web Components for Blazor library, an open-source component package that wraps the Fluent
UI Web Components for use with .NET 6.0 or higher Blazor applications.
Join our community on Discord
Join our community’s Discord space for discussions with the author and other readers:
https://packt.link/BlazorWASM2e
Table of Contents
Preface xxiii
Chapter 11: Building a Task Manager Using ASP.NET Web API 325
Chapter 12: Building an Expense Tracker Using the EditForm Component 353
Index 395
Preface
Blazor WebAssembly is a framework that enables you to build single-page web applications that
use C# on the client instead of JavaScript. It is built on the popular and robust ASP.NET framework.
Blazor WebAssembly does not rely on plugins or add-ons for you to use C# in the browser. It only
requires that the browser support WebAssembly, which all modern browsers do.
In this book, you will complete practical projects that will teach you the fundamentals of the
Blazor WebAssembly framework. Each chapter includes a stand-alone project with detailed
step-by-step instructions. Each project is designed to highlight one or more important concepts
concerning Blazor WebAssembly.
By the end of the book, you will have experience with building both simple stand-alone web
applications and hosted web applications with SQL Server backends.
This is the second edition of this book. In this edition, we have added chapters on debugging,
deploying to Microsoft Azure, and securing your application using Microsoft Azure Active Direc-
tory. Also, all the projects in the book have been updated to use the latest version of the Blazor
WebAssembly framework.
This book is for anyone who wants to learn Blazor WebAssembly quickly by emphasizing the prac-
tical over the theoretical. It uses complete, step-by-step sample projects that are easy to follow to
teach you the concepts required to develop web apps using the Blazor WebAssembly framework.
You do not need to be a professional developer to benefit from the projects in this book, but you
do need some experience with C# and HTML.
xxiv Preface
Chapter 2, Building Your First Blazor WebAssembly Application, introduces Razor components through
the creation of a simple project. This chapter is divided into two sections. The first section explains
Razor components, routing, Razor syntax, and how to use Hot Reload while developing an appli-
cation. The second section walks you step by step through the process of creating your first Blazor
WebAssembly application by using the Blazor WebAssembly App project template provided by
Microsoft. By the end of this chapter, you will be able to create a demo Blazor WebAssembly project.
Chapter 3, Debugging and Deploying a Blazor WebAssembly App, teaches you how to debug and
deploy a Blazor WebAssembly app through the creation of a simple project. This chapter is di-
vided into two sections. The first section explains debugging, logging, handling exceptions, using
ahead-of-time (AOT) compilation, and deploying an app to Microsoft Azure. The second section
walks you step by step through the process of debugging and deploying a Blazor WebAssembly
application. By the end of this chapter, you will be able to debug a simple Blazor WebAssembly
app and deploy it to Microsoft Azure.
Chapter 4, Building a Modal Dialog Using Templated Components, provides you with an introduction
to templated components through the creation of a modal dialog component. This chapter is
divided into two sections. The first section explains RenderFragment parameters, EventCallback
parameters, and CSS isolation. The second section walks you step by step through the process
of creating a modal dialog component and moving it to your own custom Razor class library. By
the end of this chapter, you will be able to create a modal dialog component and share it with
multiple projects through a Razor class library.
Preface xxv
Chapter 5, Building a Local Storage Service Using JavaScript Interoperability (JS Interop), teaches
you how to use JavaScript with Blazor WebAssembly through the creation of a local storage
service. This chapter is divided into two sections. The first section explains the reasons that you
still need to occasionally use JavaScript and how to invoke a JavaScript function from .NET. For
completeness, it also covers how to invoke a .NET method from JavaScript. Finally, it introduces
the Web Storage API that is used by the project. In the second section, it walks you step by step
through the process of creating and testing a service that writes and reads to the local storage of
the browser. By the end of this chapter, you will be able to create a local storage service by using
JS Interop to invoke JavaScript functions from a Blazor WebAssembly application.
Chapter 6, Building a Weather App as a Progressive Web App (PWA), provides you with an intro-
duction to progressive web apps through the creation of a simple weather web app. This chapter
is divided into two sections. The first section explains what a PWA is and how to create one. It
covers both manifest files and the various types of service workers. Also, it describes how to use
the CacheStorage API, the Geolocation API, and the OpenWeather One Call API that are required
by the project in this chapter. The second section walks you step by step through the process of
creating a 5-day weather forecast app and converting it into a PWA by adding a logo, a manifest
file, and a service worker. Finally, it shows you how to install and uninstall the PWA. By the end
of this chapter, you will be able to convert a Blazor WebAssembly app into a PWA by adding a
logo, a manifest file, and a service worker.
Chapter 7, Building a Shopping Cart Using Application State, explains how to use application state
through the creation of a shopping cart web app. This chapter is divided into two sections. The
first section explains application state and dependency injection. The second section walks you
step by step through the process of creating a shopping cart application. To maintain state in your
application, you will create a service that you will register in the DI container and inject into your
components. By the end of this chapter, you will be able to use dependency injection to maintain
application state within a Blazor WebAssembly app.
Chapter 8, Building a Kanban Board Using Events, provides you with an introduction to event
handling through the creation of a Kanban board web app. This chapter is divided into two sec-
tions. The first section discusses event handling, attribute splatting, and arbitrary parameters. The
second section walks you step by step through the process of creating a Kanban board application
that uses the DragEventArgs class to enable you to drag and drop tasks between the drop zones.
By the end of this chapter, you will be able to handle events in your Blazor WebAssembly app and
will be comfortable using both attribute splatting and arbitrary parameters.
xxvi Preface
Chapter 9, Uploading and Reading an Excel file, explains how to upload various types of files and
how to use the Open XML SDK to read an Excel file. This chapter is divided into two sections. The
first section explains uploading one or more files and resizing images. It also explains how to use
virtualization to render data and how to read data from Excel files. The second section walks you
step by step through the process of creating an application that can upload and read an Excel file
and then use virtualization to render the data from the Excel file. By the end of this chapter, you
will be able to upload a file into a Blazor WebAssembly app, use the Open XML SDK to read an
Excel file, and render data using virtualization.
Chapter 10, Using Azure Active Directory to Secure a Blazor WebAssembly Application, teaches you
how to secure a Blazor WebAssembly App through the creation of a simple application that dis-
plays the contents of a claim. This chapter is divided into two sections. The first section explains
the difference between authentication and authorization. It also teaches you how to work with
authentication and how to use both the Authorize attribute and the AuthorizeView component.
The second section walks you step by step through the process of adding an application to Azure
AD and using it for both authentication and authorization. By the end of this chapter, you will be
able to secure a Blazor WebAssembly app using Azure AD.
Chapter 11, Building a Task Manager Using ASP.NET Web API, provides you with an introduction to
hosted Blazor WebAssembly applications through the creation of a task manager web app. This
is the first chapter to use SQL Server. It is divided into two sections. The first section describes
the components of a hosted Blazor WebAssembly application. It also explains how to use the
HttpClient service and the various JSON helper methods to manipulate data. The last section
walks you step by step through the process of creating a task manager application that stores
its data in a SQL Server database. You will create an API controller with actions, using Entity
Framework. By the end of this chapter, you will be able to create a hosted Blazor WebAssembly
app that uses ASP.NET Web API to update data in a SQL Server database.
Chapter 12, Building an Expense Tracker Using the EditForm Component, teaches you how to use the
EditForm component through the creation of an expense tracker web app. This chapter uses SQL
Server. It is divided into two sections. The first section introduces the EditForm component, the
built-in input components, and the built-in validation components. It also explains how to use
navigation locking to prevent the user from navigating to another page before they have saved
their edits. The last section walks you step by step through the process of creating an expense
tracker application that uses the EditForm component and some of the built-in components to
add and edit expenses that are stored in a SQL Server database. By the end of this chapter, you
will be able to use the EditForm component in conjunction with the built-in components to input
and validate data that is stored in a SQL Server database.
Preface xxvii
If you are using the digital version of this book, we advise you to type the code yourself or access the code
via the GitHub repository (link available in the next section). Doing so will help you avoid any potential
errors related to the copying and pasting of code.
This book assumes that you are an experienced web developer. You should have some experience
with C# and HTML.
There are some projects that use JavaScript and CSS, but all the code is provided. Also, there are
two projects that use Entity Framework, but once again, all the code is provided.
We also have other code bundles from our rich catalog of books and videos available at https://
github.com/PacktPublishing/. Check them out!
Code in Action
Code in Action videos for this book can be viewed at (https://packt.link/CodeinAction).
Conventions used
There are several text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Add
the DeleteProduct method to the @code block.”
When we wish to draw your attention to a particular part of a code block, the relevant lines or
items are set in bold:
public class CartService : ICartService
{
public IList<Product> Cart { get; private set; }
public int Total { get; set; }
Bold: Indicates a new term, an important word, or words that you see onscreen. For example,
words in menus or dialog boxes appear in the text like this. For example: “From the Build menu,
select the Build Solution option.”
Another random document with
no related content on Scribd:
The Project Gutenberg eBook of Essays in
American history
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
IN
AMERICAN HISTORY
BY
HENRY FERGUSON, M. A.
Northam Professor of History and Political Science in
Trinity College, Hartford.
New York
JAMES POTT AND COMPANY
114 Fifth Avenue.
Copyright, 1894,
BY
JAMES POTT & CO.
CONTENTS.
i.
the quakers in new england 9
ii.
the witches 61
iii.
sir edmund andros 111
iv.
the loyalists 161
PREFACE.
These essays are presented to the public in the belief that
though what they contain be old, it is worth telling again, and in the
hope that by viewing the early history of the country from a
somewhat different stand-point from that commonly taken, light may
be thrown upon places which have been sometimes left in shadow.
The time has been when it was considered a duty to praise
every action of the resolute men who were the early settlers of New
England. In the glow of an exultant patriotism which was unwilling to
see anything but beauty in the annals of their country, and in a spirit
of reverence which made them shrink from observing their fathers’
shortcomings, the early historians of the United States dwelt lovingly
on the bright side of the colonial life, and passed over its shadows
with filial reticence. It is evident that no true conception of any period
is possible when so studied, and it is a matter for congratulation that
at the present day the subject can be treated with greater
impartiality, and that it is no longer necessary for American writers to
make up for the political and literary insignificance of their country by
boasting either of the vastness of their continent or of the Spartan
virtue of their forefathers.
In the same manner, in earlier days, when the recollection of the
struggle for independence was still vivid, patriotic Americans were
unable to recognize anything but arbitrary tyranny in the attempts
made from time to time by the English government to give unity and
organization to the group of discordant and feeble settlements, or to
see anything but what was base and servile in the sentiments that
inspired those whom they nicknamed Tories. Now, under the
influence of calmer consideration, men are beginning to admit that
something may be said for men like Andros, who strove against the
separatist spirit which seemed to New England to be the very
essence of liberty, and even for those unfortunates who valued the
connection with Great Britain more than they did the privileges of
self-government, and who were compelled in grief and sorrow, from
their devotion to their principles, to leave forever the homes they
loved. The war of secession has taught Americans to understand the
term, and appreciate the sentiment, of loyalty. It is no longer an
unmeaning word, fit only to be ridiculed in scurrilous doggerel by
patriot rhymsters, as was the case a hundred years ago, but appeals
to an answering chord in the heart of every man who remembers the
quick heart-beats and the grand enthusiasm of those four years of
struggle, the true heroic age of American history.
The paper upon The Quakers in New England is an enlargement
and revision of an article printed in the American Church Review, in
April 1889, and that upon Sir Edmund Andros has been printed by
the Historical Society of Westchester County, N. Y., before whom it
was read in October 1892, but it has been revised and enlarged.
Instead of burdening the pages with notes and references, they have
been placed together after each essay, so that they may be readily
used by those who desire to do so, and yet may not affront the eyes
of those who do not desire them.
It is impossible to give credit for every statement to every
historian who may have made it; it has been the desire of the author
to indicate his principal sources of information, and he has not
knowingly omitted any work upon which he has relied for the
historical facts presented.
Trinity College, Hartford,
October 1894.
I.
THE QUAKERS IN NEW ENGLAND.
“We have no law among us, whereby to punish any for only
declaring by words, etc., their minds and understandings
concerning the things and ways of God, as to salvation and an
eternal condition. And we, moreover, find that in those places
where these people aforesaid in this colony are most of all
suffered to declare themselves freely, and are only opposed by
arguments in discourse, there they least of all desire to come.
And we are informed that they begin to loathe this place, for that
they are not opposed by the civil authority, but, with all patience
and meekness, are suffered to say over their pretended
revelations and admonitions. Nor are they like or able to gain
many here to their way. Surely, we find that they delight to be
persecuted by civil powers; and when they are so, they are like
to gain more adherents by the conceit of their painful sufferings
19
than by consent to their pernicious sayings.”