Learning Blazor

Book description

Take advantage of your C# skills to build UI components and client-side experiences with .NET. With this practical guide, you'll learn how to use Blazor WebAssembly to develop next-generation web experiences. Built on top of ASP.NET Core, Blazor represents the future of .NET single-page applications (SPA) investments.

Author David Pine, who focuses on .NET and Azure content development at Microsoft, explains how WebAssembly enables many non-JavaScript-based programming languages to run on the client browser. In this book, you'll learn about real-time web functionality with ASP.NET Core SignalR. You'll learn strategies for bidirectional JavaScript interop. David covers component data binding, hierarchical event-driven communications, in-memory state management, and local storage.

This book shows you how to:

  • Create a feature-rich Blazor app that looks beautiful
  • Localize an enterprise-scale app as the sole developer using GitHub Actions and Azure Cognitive Services Translator service
  • Create advanced validation scenarios for input-based components with forms
  • Automatically deploy and host to Azure Static Web Apps, and rely on HTTP services
  • Utilize geolocation service native to the browser, as well as native speech synthesis and recognition
  • Author a custom modal verification mechanism for validating a user
  • Determine the best approach for building reliable, architecturally sound websites

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Why Blazor?
    2. Who Should Read This Book
      1. For .NET developers
      2. For web developers
    3. Why I Wrote This Book
    4. How To Use This Book
    5. Roadmap And Goals Of This Book
    6. Conventions Used In This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How To Contact Us
    10. Acknowledgments
  2. 1. Blazing Into Blazor
    1. The Origin Of Blazor
    2. Blazor Hosting
      1. Blazor Server
      2. Blazor WebAssembly
      3. Blazor Hybrid
    3. Single-Page Applications, Redefined
    4. Why Adopt Blazor
      1. .NET’s Potential In The Browser
      2. .NET Is Here To Stay
      3. Familiarity
      4. Safe And Secure
      5. Code Reuse
      6. Tooling
      7. Open-Source Software
    5. Your First Blazor App With The .NET CLI
      1. Build The App
      2. Install Dev-cert
      3. Run The App
    6. The Code Must Live On
    7. Perusing The “Learning Blazor” Sample App
    8. Summary
  3. 2. Executing The App
    1. Requesting The Initial Page
    2. App Startup And Bootstrapping
    3. Blazor WebAssembly App Internals
      1. Detecting Client Culture At Startup
      2. Layouts, Shared Components, And Navigation
    4. Summary
  4. 3. ​​Componentizing
    1. Design With The User In Mind
      1. Leveraging “Pwned” Functionality
      2. Have I Been Pwned Client Services
      3. Restricting Access To Resources
    2. The Introduction Component Says “Hi”
    3. The Joke Component And Services
      1. Aggregating Joke Services — Laughter Ensues
    4. Forecasting Local Weather
    5. Summary
  5. 4. Customizing The User Login Experience
    1. A Bit More On Blazor Authentication
      1. Client-side Custom Authorization Message Handler Implementation
      2. The Web.Client ConfigureServices Functionality
    2. Native Speech Synthesis
      1. Sharing And Consuming Custom Components
    3. Chrome: The overloaded term
      1. Modal Modularity And Blazor Component Hierarchies
      2. Exploring Blazor Event Binding
    4. Summary
  6. 5. Localizing The App
    1. What Is Localization?
    2. The Localization Process
    3. The Language Selection Component
    4. Automating Translations With GitHub Actions
      1. Localization In Action
    5. Summary
  7. 6. Exemplifying Real-time Web Functionality
    1. Defining The Server-side Events
      1. Exposing Twitter Streams And Chat Functionality
      2. Writing Contextual RPC And Inner-Process Communication
      3. Configuring The Hub Endpoint
    2. Consuming Real-time Data On The Client
      1. Configuring The Client
      2. Sharing A Hub Connection
      3. Consuming Real-time Data In Components
    3. Summary
  8. 7. Using Source Generators
    1. What Are Source Generators?
    2. Building A Case For Source Generators
      1. Evaluating TypeScript Declarations
    3. C# Source Generators In Action
      1. Source Generating The localStorage API
      2. Source Generating The geolocation API
      3. Example Usage of the ILocalStorageService
    4. Summary
  9. 8. Accepting Form Input with Validation
    1. The Basics Of Form Submission
    2. Framework-provided Components For Forms
    3. Models And Data Annotations
      1. Defining Component Models
      2. Defining And Consuming Validation Attributes
    4. Implementing A Contact Form
    5. Implementing Speech Recognition As User Input
      1. Reactive Programming With The Observer Pattern
      2. Managing Callbacks With A Registry
      3. Applying The Speech Recognition Service To Components
    6. Form Submission Validation And Verification
    7. Summary
  10. 9. Testing All the Things
    1. Why Test?
    2. Unit Testing
      1. Defining Unit Testable Code
      2. Writing An Extension Method Unit Test
    3. Component Testing
    4. End-to-End Testing with Playwright
    5. Automating Test Execution
    6. Summary
  11. A. Learning Blazor App Projects
    1. Web Client
    2. Web API
    3. Pwned Web API
    4. Web Abstractions
    5. Web Extensions
    6. Web HTTP Extensions
    7. Web Functions
    8. Web Joke Services
    9. Web Models
    10. Web Twitter Components
    11. Web Twitter Services
  12. About the Author

Product information

  • Title: Learning Blazor
  • Author(s): David Pine
  • Release date: October 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098113247