Book Image

Mastering Blazor WebAssembly

By : Ahmad Mozaffar
3.5 (2)
Book Image

Mastering Blazor WebAssembly

3.5 (2)
By: Ahmad Mozaffar

Overview of this book

Blazor WebAssembly is a revolutionary technology in software development that enables you to develop web applications with a rich user interface using C# without JavaScript. It can be run natively in the browser and soon on mobile apps with .NET MAUI, making it a superweapon in the .NET developer’s toolbox. This capability has opened the doors for the JavaScript community to have a stable framework to build single page applications (SPAs) maintained by Microsoft and driven by the community. Mastering Blazor WebAssembly is a complete resource that teaches you everything you need to build client-side web applications using C# & .NET 7.0. Throughout this book, you’ll discover the anatomy of a Blazor WebAssembly project, along with the build, style, and structure of the components. You’ll implement forms to catch user input and collect data, as well as explore the topics of navigating between the pages in depth. The chapters will guide you through handling complex scenarios like RenderTrees, writing efficient unit tests, using variant security methods, and publishing the app to different providers, all in a practical manner. By the end of this book, you’ll have the skills necessary to build web apps with Blazor WebAssembly, along with the basics for a future in mobile development with .NET MAUI and Blazor.
Table of Contents (21 chapters)
1
Part 1: Blazor WebAssembly Essentials
5
Part 2: App Parts and Features
13
Part 3: Optimization and Deployment

What this book covers

Chapter 1, Understanding the Anatomy of a Blazor WebAssembly Project, introduces Blazor WebAssembly, guides you to set up a project and understand its structure, and covers essential topics such as environments and dependency injection.

Chapter 2, Components in Blazor, explains the concept of components in Blazor WebAssembly and SPAs, covering how to build, communicate, and style them.

Chapter 3, Developing Advanced Components in Blazor, introduces advanced component types such as layouts, templated components, and dynamic components, showing you how to use Razor class library projects to build reusable components.

Chapter 4, Navigation and Routing, explains the navigation process in a SPA and how to implement it in your Blazor apps. The chapter also covers how to use query parameters, send and receive data via a URL, and respond to navigation changes.

Chapter 5, Capturing User Input with Forms and Validations, explains how to create and submit forms in Blazor, use the built-in input components, validate user input, and create your own custom input component.

Chapter 6, Consuming JavaScript in Blazor, explains how and when to use JS in your Blazor WebAssembly project and how to call JS code from your Blazor app, and vice versa. It also shows how to wrap an existing JS package into a Blazor component using JS.

Chapter 7, Managing Application State, introduces the concept of state management in an SPA and shows three different techniques for preserving the state of your application – using local storage, in memory, or a URL.

Chapter 8, Consuming Web APIs from Blazor WebAssembly, provides an overview of web APIs and web API clients, showing you how to understand an existing web API and send HTTP requests to it from Blazor. It also covers delegating handlers, IHttpClientFactory, and how to organize API calls in your app.

Chapter 9, Authenticating and Authorizing Users in Blazor, explains what authentication and authorization are, and then deep-dives into how Blazor handles authentication and how to develop your custom authentication flow with JSON Web Tokens. It also shows you how to control the UI and the app logic based on the authentication state and call secured web API endpoints.

Chapter 10, Handling Errors in Blazor WebAssembly, shows you how to make your app reliable and the techniques to handle errors efficiently in your apps.

Chapter 11, Giving Your App a Speed Boost, provides you with advanced mechanisms in Blazor that help you make your app as efficient as possible, by increasing the rendering speed and reducing the app size for faster load time.

Chapter 12, RenderTree in Blazor, explains in detail how Blazor renders components and manages the Document Object Model (DOM), introducing the concept of RenderTree. It also shows how you can improve your app performance by learning how things work under the hood.

Chapter 13, Testing Blazor WebAssembly Apps, introduces the concept of component testing and the bUnit library, providing you with what you need to write efficient unit tests for your components. The chapter also covers End-to-End (E2E) testing and the Playwright package.

Chapter 14, Publishing Blazor WebAssembly Apps, shows the checks to do before publishing an app, introduces the Blazor WebAssembly ASP.NET Core Hosted app model, and guides you step by step to release your apps to Azure App Service and Azure Static Web Apps.

Chapter 15, What’s Next?, provides an overview of more components and use cases to help you apply what you learned in this book.