Blazor Web Development Cookbook: Tested recipes for advanced single-page application scenarios in .NET 9

Blazor Web Development Cookbook: Tested recipes for advanced single-page application scenarios in .NET 9

Blazor Web Development Cookbook: Tested recipes for advanced single-page application scenarios in .NET 9
Автор: Bazyluk Pawel
Дата выхода: 2024
Издательство: Packt Publishing Limited
Количество страниц: 282
Размер файла: 2,0 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

Cover....1

Title Page....2

Copyright and Credits....3

Dedicated....4

Contributor....5

Table of Contents....8

Preface....16

Chapter 1: Working with Component-Based Architecture....24

Technical requirements....25

Initializing a project....25

Getting ready....25

How to do it.......26

How it works.......28

There’s more.......29

Creating your first basic component....29

Getting ready....30

How to do it.......30

How it works.......30

There’s more.......31

Declaring parameters on a component....31

Getting ready....31

How to do it.......31

How it works.......32

There’s more.......33

Detecting render mode at runtime....33

Getting ready....34

How to do it.......34

How it works.......34

Ensuring that a parameter is required....35

Getting ready....35

How to do it.......36

How it works.......37

Passing values from the parent component with CascadingParameter....37

Getting ready....37

How to do it.......38

How it works.......39

There’s more.......40

Creating components with customizable content....40

Getting ready....41

How to do it.......41

How it works.......42

There’s more.......43

Making components generic....44

Getting ready....44

How to do it.......44

How it works.......46

There’s more.......47

Decoupling components with DynamicComponent....47

Getting ready....48

How to do it.......48

How it works.......50

Chapter 2: Synchronous and Asynchronous Data Binding....52

Technical requirements....53

Binding values with markup elements....53

Getting ready....53

How to do it…....53

How it works…....54

Binding to a specific DOM event....54

Getting ready....55

How to do it…....55

How it works…....56

There’s more…....56

Performing asynchronous actions after binding....57

Getting ready....57

How to do it…....58

How it works…....59

There’s more…....60

Customizing get and set binding logic....60

Getting ready....61

How to do it…....61

How it works…....61

There’s more…....62

Simplifying binding with the bind-Value pattern....62

Getting ready....63

How to do it…....63

How it works…....65

Binding with an external data provider....66

Getting ready....66

How to do it…....67

How it works…....68

Chapter 3: Taking Control of Event Handling....70

Technical requirements....71

Hooking into event delegates....71

Getting ready....71

How to do it…....71

How it works…....73

There’s more…....73

Delegating with lambda expressions....74

Getting ready....74

How to do it…....75

How it works…....76

See also....76

Delegating with EventCallback....76

Getting ready....77

How to do it…....77

How it works…....78

There’s more…....79

Preventing default event actions....79

Getting ready....79

How to do it…....80

How it works…....81

There’s more…....81

Controlling event propagation....82

Getting ready....82

How to do it…....82

How it works…....83

There’s more…....84

Introducing custom events....84

Getting ready....84

How to do it…....85

How it works…....87

There’s more…....87

Handling long-running events....88

Getting ready....88

How to do it…....88

How it works…....91

There’s more…....93

Chapter 4: Enhancing Data Display with Grids....94

Technical requirements....95

Refactoring a table to a grid component....95

Getting ready....95

How to do it…....95

How it works…....97

There’s more…....97

Attaching actions to parts of a grid....98

Getting ready....99

How to do it…....99

How it works…....102

There’s more…....104

Implementing pagination....105

Getting ready....105

How to do it…....105

How it works…....108

There’s more…....110

See also....110

Implementing sorting....110

Getting ready....110

How to do it…....111

How it works…....112

Implementing infinite scrolling....114

Getting ready....114

How to do it…....114

How it works…....116

There’s more…....117

Utilizing QuickGrid....117

Getting ready....117

How to do it…....118

How it works…....119

Chapter 5: Managing Application State....120

Technical requirements....121

Having bookmarkable state....121

Getting ready....121

How to do it…....121

How it works…....123

There’s more…....123

Implementing an in-memory state container....124

Getting ready....124

How to do it…....124

How it works…....127

There’s more…....128

Injecting application state as a service....128

Getting ready....128

How to do it…....129

How it works…....130

See also....131

Invoking state changes from anywhere....131

Getting ready....131

How to do it…....132

How it works…....134

There’s more…....135

Persisting state....135

Getting ready....135

How to do it…....136

How it works…....138

There’s more…....140

Resolving persisted state....140

Getting ready....140

How to do it…....141

How it works…....142

There’s more…....143

Sharing state across interactive render mode boundaries....143

Getting ready....143

How to do it…....144

How it works…....146

There’s more…....147

Chapter 6: Building Interactive Forms....148

Technical requirements....149

Binding a simple model to a form....149

Getting ready....149

How to do it…....149

How it works…....150

There’s more....151

Submitting static forms without full page reload....151

Getting ready....152

How to do it…....152

How it works…....152

There’s more…....153

Binding nested models to a form....153

Getting ready....153

How to do it…....154

How it works…....154

There’s more…....155

Utilizing built-in input components....155

Getting ready....155

How to do it…....156

How it works…....157

Handling file uploads with a form....159

Getting ready....159

How to do it…....159

How it works…....160

There’s more…....161

Securing a form with an anti-forgery token....163

Getting ready....163

How to do it…....163

How it works…....164

There’s more…....165

See also....165

Chapter 7: Validating User Input Forms....166

Technical requirements....167

Adding validation to a form....167

Getting ready....168

How to do it…....168

How it works…....170

There’s more…....171

Leveraging data annotations for form validation....172

Getting ready....172

How to do it…....172

How it works…....173

There’s more…....174

Implementing custom validation attributes....174

Getting ready....174

How to do it…....175

How it works…....176

There’s more…....177

Validating complex data models....178

Getting ready....178

How to do it…....178

How it works…....180

There’s more…....181

Styling validation messages....181

Getting ready....181

How to do it…....182

How it works…....183

There’s more…....184

Displaying a toast when validation fails....184

Getting ready....185

How to do it…....185

How it works…....186

Enabling a submit option based on the form state....188

Getting ready....188

How to do it…....188

How it works…....189

There’s more…....190

Chapter 8: Keeping the Application Secure....192

Technical requirements....193

Scaffolding identity....193

Getting ready....193

How to do it…....193

How it works…....196

There’s more…....200

Securing pages....201

Getting ready....201

How to do it…....201

How it works…....201

There’s more…....202

Securing markup areas....202

Getting ready....202

How to do it…....203

How it works…....203

There’s more…....203

Creating roles....204

Getting ready....204

How to do it…....205

How it works…....207

Modifying a user’s identity....208

Getting ready....208

How to do it…....208

How it works…....211

See also....213

Supporting roles’ and policies’ authorization....213

Getting ready....213

How to do it…....213

How it works…....215

There’s more…....217

Resolving authentication state in procedural logic....218

Getting ready....218

How it works…....220

Chapter 9: Exploring Navigation and Routing....222

Technical requirements....223

Enabling routes from multiple assemblies....224

Getting ready....224

How to do it…....224

How it works…....225

Working with parameterized routes....226

Getting ready....226

How to do it…....226

How it works…....227

There’s more…....228

See also....228

Working with query parameters....228

Getting ready....228

How to do it…....229

How it works…....229

There’s more…....229

See also....230

Implementing unified deep linking....230

Getting ready....230

How to do it…....230

How it works…....231

There’s more…....231

Handling incorrect navigation requests....232

Getting ready....232

How to do it…....232

How it works…....232

See also....233

Executing an asynchronous operation with navigation....233

Getting ready....233

How to do it…....233

How it works…....234

See also....235

Canceling a long-running task when users navigate away....235

Getting ready....235

How to do it…....235

How it works…....237

Controlling navigation history....238

Getting ready....238

How to do it…....239

How it works…....239

Chapter 10: Integrating with OpenAI....240

Technical requirements....241

Setting up an Azure OpenAI service....241

Getting ready....241

How to do it…....242

How it works…....250

There’s more…....251

See also....253

Implementing smart pasting....253

Getting ready....253

How to do it…....254

How it works…....256

There’s more…....257

Implementing a smart text area....258

Getting ready....258

How to do it…....259

How it works…....259

There’s more…....260

See also....261

Adding a ChatBot....261

Getting ready....261

How to do it…....262

How it works…....265

There’s more…....267

See also....267

Connecting an Azure OpenAI service to an existing data index....268

Getting ready....268

How to do it…....268

How it works…....270

There’s more…....270

See also....271

Index....272

Other Books You May Enjoy....279

Master web development with Blazor in .NET 9, gaining advanced skills while working with dynamic components to secure and optimize your applications

Key Features

  • Develop generic, customizable components secured with roles and policies
  • Manage application and user states, in simple to complex scenarios, across render boundaries
  • Enhance user experience by embedding AI-powered features into the application
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

With support for both server-side and client-side hosting, as well as the flexibility to mix render modes, Blazor empowers you to leverage cloud computing while maintaining the performance of local applications. Paweł Bazyluk—a Blazor expert with over a decade of experience in .NET technologies—shows you how Blazor, a Microsoft framework, enables you to create interactive web applications using C# and .NET, while reducing reliance on JavaScript. This cookbook highlights Blazor’s vast possibilities using practical recipes that address key aspects of web development and showcase the framework's versatility in building modern, integrated applications.

Pawel demonstrates how to skillfully navigate component-based architecture, and create, parameterize, and customize components to achieve high modularity. Working through practical insights and hands-on guidance in each chapter, you’ll progress from advanced data binding and event handling intricacies to optimizing data display using grids. You’ll explore application state management, build interactive forms with validation, leverage Blazor’s routing engine, and keep every part of the application secure. The book also explores cutting-edge topics, touching on how to enhance your application with AI-powered features.

By the end of the book, you’ll be fully equipped to build robust, scalable, and secure web applications in Blazor.

What you will learn

  • Build modular, reusable, maintainable code in component-based architecture
  • Exchange data between a UI and external service while ensuring UI responsiveness
  • Implement efficient user interactions and event handling
  • Present data in a structured and user-friendly manner using grids
  • Understand state management strategies crucial for complex applications
  • Create user-friendly and robust data input forms with smart validations
  • Explore routing capabilities and leverage navigation events
  • Enhance forms with AI-powered features and implement your own AI chatbot

Who this book is for

This book is for developers with a foundational understanding of Blazor and .NET seeking proven solutions to common web application development challenges. Frontend engineers, .NET developers, and solution architects looking to gain full-stack expertise will also find this resource invaluable. Familiarity with HTML, CSS, and JavaScript programming will help you get the most out of this web development book.


Похожее:

Список отзывов:

Нет отзывов к книге.