Author(s): Mark J. Price
Edition: 1
Publisher: Packt Publishing
Year: 2022
Language: English
Pages: 815
Cover
Quick Chapter Reference
Table of Contents
Preface
Chapter 1: Introducing Apps and Services with .NET
Introducing this book and its contents
A companion book to continue your learning journey
What you will learn in this book
My learning philosophy
Fixing my mistakes
Project naming and port numbering conventions
Treating warnings as errors
App and service technologies
Building websites and apps using ASP.NET Core
Building web and other services
Windows Communication Foundation (WCF)
Summary of choices for services
Building Windows-only apps
Understanding legacy Windows application platforms
Understanding modern .NET support for legacy Windows platforms
Building cross-platform mobile and desktop apps
.NET MAUI alternatives
Understanding Uno platform
Understanding Avalonia
Setting up your development environment
Choosing the appropriate tool and application type for learning
Using Visual Studio Code for cross-platform development
Using GitHub Codespaces for development in the cloud
Using Visual Studio for Mac for general development
Using Visual Studio for Windows for general development
What I used
Deploying cross-platform
Downloading and installing Visual Studio 2022 for Windows
Visual Studio 2022 for Windows keyboard shortcuts
Downloading and installing Visual Studio Code
Installing other extensions
Understanding Visual Studio Code versions
Visual Studio Code keyboard shortcuts
Finding the solution code on GitHub
Consuming Azure resources
Using an analyzer to write better code
Suppressing warnings
Fixing the code
What’s new in C# and .NET?
Understanding .NET support
Understanding .NET Runtime and .NET SDK versions
What’s new in C# 8 and .NET Core 3?
Default interface methods
Switch expressions
Using declarations
Nullable reference types
Indices and ranges
What’s new in C# 9 and .NET 5?
Record types and init-only setters
Top-level statements
Target-typed new
What’s new in C# 10 and .NET 6?
Top-level statements and implicitly imported namespaces by default
Checking for null in method parameters
What’s new in C# 11 and .NET 7?
Raw string literals
Requiring properties to be set during instantiation
Generic math support
Making good use of the GitHub repository for this book
Raising issues with the book
Giving me feedback
Downloading solution code from the GitHub repository
Where to go for help
Reading Microsoft documentation
Getting help for the dotnet tool
Searching for answers using Google
Subscribing to the official .NET blog
Watching Scott Hanselman’s videos
Practicing and exploring
Exercise 1.1 – Test your knowledge
Exercise 1.2 – Explore topics
Summary
Chapter 2: Managing Relational Data Using SQL Server
Understanding modern databases
Using a sample relational database
Connecting to a SQL Server database
Installing and setting up SQL Server
Installing SQL Server Developer Edition for Windows
Visual Studio Code extension for working with SQL Server
Creating the Northwind sample database on Windows
Setting up Azure SQL Database
Installing Azure SQL Edge in Docker
Managing data with Transact-SQL
T-SQL data types
Documenting with comments
Declaring variables
Specifying data types
Controlling flow
Operators
Data Manipulation Language (DML)
DML for adding, updating, and deleting data
Data Definition Language (DDL)
Managing data with low-level APIs
Understanding the types in ADO.NET
Creating a console app for working with ADO.NET
Executing queries and working with data readers using ADO.NET
Working with ADO.NET asynchronously
Executing stored procedures using ADO.NET
Managing data with EF Core
Understanding Entity Framework Core
Scaffolding models using an existing database
Setting up the dotnet-ef tool
Defining EF Core models
Using EF Core conventions to define the model
Using EF Core annotation attributes to define the model
Using the EF Core Fluent API to define the model
Understanding data seeding with the Fluent API
Defining the Northwind database model
Querying the Northwind model
Mapping inheritance hierarchies with EF Core
Table-per-hierarchy (TPH) mapping strategy
Table-per-type (TPT) mapping strategy
Table-per-concrete-type (TPC) mapping strategy
Configuring inheritance hierarchy mapping strategies
Example of hierarchy mapping strategies
Building a reusable entity data model
Creating a class library for entity models using SQL Server
Creating a class library for the data context using SQL Server
Calculated properties on entity creation
Creating a test project to check the integration of the class libraries
Writing unit tests for entity models
Running unit tests using Visual Studio 2022
Running unit tests using Visual Studio Code
Cleaning up data resources
Removing Azure resources
Removing Docker resources
Practicing and exploring
Exercise 2.1 – Test your knowledge
Exercise 2.2 – Practice benchmarking ADO.NET against EF Core
Exercise 2.3 – Explore topics
Exercise 2.4 – Explore Dapper
Summary
Chapter 3: Managing NoSQL Data Using Azure Cosmos DB
Understanding NoSQL databases
Cosmos DB and its APIs
Document modeling
Consistency levels
Hierarchy of components
Throughput provisioning
Partition strategies
Data storage design
Migrating data to Cosmos DB
Creating Cosmos DB resources
Using an emulator on Windows to create Azure Cosmos DB resources
Using the Azure portal to create Azure Cosmos DB resources
Using a .NET app to create Azure Cosmos DB resources
Manipulating data with Core (SQL) API
Performing CRUD operations with Cosmos SQL API
Understanding SQL queries
Understanding server-side programming
Manipulating graph data with Gremlin API
Cleaning up Azure resources
Practicing and exploring
Exercise 3.1 – Test your knowledge
Exercise 3.2 – Practice data modeling and partitioning
Exercise 3.3 – Explore topics
Exercise 3.4 – Explore NoSQL databases
Exercise 3.5 – Download cheat sheets
Exercise 3.6 – Read a Gremlin guide
Summary
Chapter 4: Benchmarking Performance, Multitasking, and Concurrency
Understanding processes, threads, and tasks
Monitoring performance and resource usage
Evaluating the efficiency of types
Monitoring performance and memory using diagnostics
Useful members of the Stopwatch and Process types
Implementing a Recorder class
Measuring the efficiency of processing strings
Monitoring performance and memory using Benchmark.NET
Running tasks asynchronously
Running multiple actions synchronously
Running multiple actions asynchronously using tasks
Starting tasks
Waiting for tasks
Using wait methods with tasks
Continuing with another task
Nested and child tasks
Wrapping tasks around other objects
Synchronizing access to shared resources
Accessing a resource from multiple threads
Applying a mutually exclusive lock to a conch
Understanding the lock statement
Avoiding deadlocks
Synchronizing events
Making CPU operations atomic
Applying other types of synchronization
Understanding async and await
Improving responsiveness for console apps
Working with async streams
Improving responsiveness for GUI apps
Improving scalability for web applications and web services
Common types that support multitasking
Using await in catch blocks
Practicing and exploring
Exercise 4.1 – Test your knowledge
Exercise 4.2 – Explore topics
Exercise 4.3 – Read more about parallel programming
Summary
Chapter 5: Implementing Popular Third-Party Libraries
Which third-party libraries are most popular?
What is covered in my books
What could be covered in my books
Working with images
Generating grayscale thumbnails
ImageSharp packages for drawing and the web
Logging with Serilog
Structured event data
Serilog sinks
Logging to the console and a rolling file with Serilog
Mapping between objects
Testing an AutoMapper configuration
Performing live mappings between models
Making fluent assertions in unit testing
Making assertions about strings
Making assertions about collections and arrays
Making assertions about dates and times
Validating data
Understanding the built-in validators
Performing custom validation
Customizing validation messages
Defining a model and validator
Testing the validator
Integrating with ASP.NET Core
Generating PDFs
Creating class libraries to generate PDF documents
Creating a console app to generate PDF documents
Practicing and exploring
Exercise 5.1 – Test your knowledge
Exercise 5.2 – Explore topics
Summary
Chapter 6: Observing and Modifying Code Execution Dynamically
Working with reflection and attributes
Versioning of assemblies
Reading assembly metadata
Creating custom attributes
Understanding compiler-generated types and members
Making a type or member obsolete
Dynamically loading assemblies and executing methods
Doing more with reflection
Working with expression trees
Understanding components of expression trees
Executing the simplest expression tree
Creating source generators
Implementing the simplest source generator
Doing more with source generators
Practicing and exploring
Exercise 6.1 – Test your knowledge
Exercise 6.2 – Explore topics
Summary
Chapter 7: Handling Dates, Times, and Internationalization
Working with dates and times
Specifying date and time values
Formatting date and time values
Date and time calculations
Microseconds and nanoseconds
Globalization with dates and times
Localizing the DayOfWeek enum
Working with only a date or a time
Working with time zones
Understanding DateTime and TimeZoneInfo
Exploring DateTime and TimeZoneInfo
Working with cultures
Detecting and changing the current culture
Temporarily using the invariant culture
Localizing your user interface
Defining and loading resources
Testing globalization and localization
Practicing and exploring
Exercise 7.1 – Test your knowledge
Exercise 7.2 – Explore topics
Exercise 7.3 – Learn from expert Jon Skeet
Summary
Chapter 8: Protecting Your Data and Applications
Understanding the vocabulary of protection
Keys and key sizes
IVs and block sizes
Salts
Generating keys and IVs
Encrypting and decrypting data
Encrypting symmetrically with AES
Hashing data
Hashing with the commonly used SHA256
Signing data
Signing with SHA256 and RSA
Generating random numbers
Generating random numbers for games and similar apps
Generating random numbers for cryptography
Authenticating and authorizing users
Authentication and authorization mechanisms
Identifying a user
User membership
Implementing authentication and authorization
Protecting application functionality
Real-world authentication and authorization
Practicing and exploring
Exercise 8.1 – Test your knowledge
Exercise 8.2 – Practice protecting data with encryption and hashing
Exercise 8.3 – Practice protecting data with decryption
Exercise 8.4 – Explore topics
Exercise 8.5 – Review Microsoft encryption recommendations
Summary
Chapter 9: Building and Securing Web Services Using Minimal APIs
Building web services using ASP.NET Core Minimal APIs
Understanding Minimal APIs route mappings
Understanding parameter mapping
Understanding return values
Documenting a Minimal APIs service
Setting up an ASP.NET Core Web API project
Testing web services using Visual Studio Code extensions
Excluding paths from OpenAPI documentation
Relaxing the same origin security policy using CORS
Configuring HTTP logging for the web service
Creating a web page JavaScript client
Creating a .NET client
Understanding CORS
Enabling CORS for specific endpoints
Understanding other CORS policy options
Preventing denial-of-service attacks using rate limiting
Rate limiting using the AspNetCoreRateLimit package
Creating a rate-limited console client
Rate limiting using ASP.NET Core middleware
Understanding identity services
JWT bearer authorization
Authenticating service clients using JWT bearer authentication
Practicing and exploring
Exercise 9.1 – Test your knowledge
Exercise 9.2 – Review Microsoft HTTP API design policy
Exercise 9.3 – Explore topics
Summary
Chapter 10: Exposing Data via the Web Using OData
Understanding OData
Understanding the OData standard
Understanding OData queries
Building a web service that supports OData
Defining OData models for the EF Core models
Testing the OData models
Creating and testing OData controllers
Testing OData services using Visual Studio Code extensions
Querying OData services using REST Client
Understanding OData standard query options
Understanding OData operators
Understanding OData functions
Exploring OData queries
Using logs to review the efficiency of OData requests
Versioning OData controllers
Enabling entity inserts, updates, and deletes
Building clients for OData services
Calling services in the Northwind MVC website
Revisiting the introductory query
Practicing and exploring
Exercise 10.1 – Test your knowledge
Exercise 10.2 – Explore topics
Summary
Chapter 11: Combining Data Sources Using GraphQL
Understanding GraphQL
GraphQL query document format
Requesting fields
Specifying filters and arguments
Understanding other GraphQL capabilities
Understanding the ChilliCream GraphQL platform
Building a service that supports GraphQL
Defining the GraphQL schema for Hello World
Writing and executing GraphQL queries
Naming GraphQL queries
Understanding field conventions
Defining GraphQL queries for EF Core models
Adding support for EF Core
Exploring GraphQL queries with Northwind
Building a .NET client for a GraphQL service
Understanding GraphQL responses
Using REST Client as a GraphQL client
Using an ASP.NET Core MVC project as a GraphQL client
Testing the .NET client
Understanding Strawberry Shake
Creating a console app client
Implementing GraphQL mutations
Practicing and exploring
Exercise 11.1 – Test your knowledge
Exercise 11.2 – Explore topics
Exercise 11.3 – Practice building .NET clients
Summary
Chapter 12: Building Efficient Microservices Using gRPC
Understanding gRPC
How gRPC works
Defining gRPC contracts with .proto files
gRPC benefits
gRPC limitations
Types of gRPC methods
Microsoft’s gRPC packages
Building a gRPC service and client
Building a Hello World gRPC service
Building a Hello World gRPC client
Testing a gRPC service and client
Implementing gRPC for an EF Core model
Implementing the gRPC service
Implementing the gRPC client
Getting request and response metadata
Adding a deadline for higher reliability
Implementing gRPC JSON transcoding
Enabling gRPC JSON transcoding
Testing gRPC JSON transcoding
Comparing with gRPC-Web
Practicing and exploring
Exercise 12.1 – Test your knowledge
Exercise 12.2 – Explore topics
Summary
Chapter 13: Broadcasting Real-Time Communication Using SignalR
Understanding SignalR
The history of real-time communication on the web
AJAX
WebSocket
Introducing SignalR
Azure SignalR Service
Designing method signatures
Building a live communication service using SignalR
Defining some shared models
Enabling a server-side SignalR hub
Building a web client using the SignalR JavaScript library
Adding a chat page to the MVC website
Testing the chat feature
Building a .NET console app client
Creating a .NET client for SignalR
Testing the .NET console app client
Streaming data using SignalR
Defining a hub for streaming
Creating a .NET console app client for streaming
Testing the streaming service and client
Practicing and exploring
Exercise 13.1 – Test your knowledge
Exercise 13.2 – Explore topics
Summary
Chapter 14: Building Serverless Nanoservices Using Azure Functions
Understanding Azure Functions
Azure Functions triggers and bindings
NCRONTAB expressions
Azure Functions versions and languages
Azure Functions hosting models
Azure Functions hosting plans
Azure Storage requirements
Testing locally with Azurite
Azure Functions authorization levels
Azure Functions support for dependency injection
Installing Azure Functions Core Tools
Building an Azure Functions project
Using Visual Studio 2022
Using Visual Studio Code
Using the func CLI
Reviewing the Azure Functions project
Implementing a simple function
Testing a simple function
Responding to timer and resource triggers
Implementing a timer triggered function
Testing the Timer triggered function
Implementing a function that works with queues and BLOBs
Testing the function that works with queues and BLOBs
Publishing an Azure Functions project to the cloud
Using Visual Studio 2022 to publish
Using Visual Studio Code to publish
Cleaning up Azure Functions resources
Practicing and exploring
Exercise 14.1 – Test your knowledge
Exercise 14.2 – Explore topics
Summary
Chapter 15: Building Web User Interfaces Using ASP.NET Core
Setting up an ASP.NET Core MVC website
Creating an ASP.NET Core MVC website
Exploring the default ASP.NET Core MVC website
Understanding visitor registration
Reviewing an MVC website project structure
Referencing an EF Core class library and registering a data context
Defining web user interfaces with Razor views
Understanding Razor views
Prototyping with Bootstrap
Breakpoints and containers
Rows and columns
Color themes
Tables
Buttons and links
Badges
Alerts
Good practice for Bootstrap
Understanding Razor syntax and expressions
Understanding HTML Helper methods
Defining a strongly typed Razor view
Localizing and globalizing with ASP.NET Core
Creating resource files
Using Visual Studio 2022
Using Visual Studio Code
Localizing Razor views with an injected view localizer
Understanding the Accept-Language header
Defining web user interfaces with Tag Helpers
Comparing HTML Helpers and Tag Helpers
Exploring the Anchor Tag Helper
Exploring the Cache Tag Helpers
Exploring the Environment Tag Helper
Understanding how cache busting with Tag Helpers works
Exploring Forms-related Tag Helpers
Practicing and exploring
Exercise 15.1 – Test your knowledge
Exercise 15.2 – Practice building user interfaces with Bootstrap
Exercise 15.3 – Explore topics
Summary
Chapter 16: Building Web Components Using Blazor WebAssembly
Understanding Blazor
Blazor hosting models
Deployment choices for Blazor WebAssembly apps
The browser compatibility analyzer for Blazor WebAssembly
CSS and JavaScript isolation
Blazor components
Blazor routing to page components
How to pass route parameters
Setting parameters from a query string
Route constraints for parameters
Base component classes
How to navigate Blazor routes to page components
Building Blazor components
Building and testing a Blazor progress bar component
Building and testing a Blazor dialog box component
Building and testing a Blazor alert component
Building a Blazor data component
Making the component a routable page component
Getting entities into a component by building a web service
Getting entities into a component by calling the web service
Implementing caching using local storage
Interop with JavaScript modules
Building a local storage service
Building Progressive Web Apps
Implementing offline support for PWAs
Practicing and exploring
Exercise 16.1 – Test your knowledge
Exercise 16.2 – Practice building Blazor components
Exercise 16.3 – Practice building an IndexedDB interop service
Exercise 16.4 – Explore topics
Summary
Chapter 17: Leveraging Open-Source Blazor Component Libraries
Understanding open-source Blazor component libraries
Exploring Radzen Blazor components
Enabling the Radzen dialog, notification, context menu, and tooltip components
Using the Radzen tooltip and context menu components
Using the Radzen notification and dialog components
Building a web service for Northwind entities
Using the Radzen tabs, image, and icon components
Using the Radzen HTML editor component
Using the Radzen chart component
Using the Radzen form components
Testing the employees page component
Practicing and exploring
Exercise 17.1 – Test your knowledge
Exercise 17.2 – Practice by exploring MudBlazor
Exercise 17.3 – Explore topics
Summary
Chapter 18: Building Mobile and Desktop Apps Using .NET MAUI
Understanding XAML
Simplifying code using XAML
.NET MAUI namespaces
Type converters
Choosing between .NET MAUI controls
Markup extensions
Understanding .NET MAUI
Development tools for mobile first, cloud first
Installing .NET MAUI workloads manually
Using Windows to create iOS and macOS apps
.NET MAUI user interface components
Shell control
ListView control
Entry and Editor controls
.NET MAUI handlers
Writing platform-specific code
Building mobile and desktop apps using .NET MAUI
Creating a virtual Android device for local app testing
Enabling Windows developer mode
Creating a .NET MAUI solution
Adding shell navigation and more content pages
Implementing more content pages
Using shared resources
Defining resources to share across an app
Referencing shared resources
Changing shared resources dynamically
Using data binding
Binding to elements
Understanding MVVM
INotifyPropertyChanged interface
ObservableCollection class
Creating a view model with two-way data binding
Creating views for the customers list and customer details
Testing the .NET MAUI app
Consuming a web service from a mobile app
Creating a Minimal API web service for customers
Configuring the web service to allow unsecure requests
Connecting to local web services while testing
Configuring the iOS app to allow unsecure connections
Configuring the Android app to allow unsecure connections
Getting customers from the web service
Practicing and exploring
Exercise 18.1 – Test your knowledge
Exercise 18.2 – Explore topics
Summary
Chapter 19: Integrating .NET MAUI Apps with Blazor and Native Platforms
Building .NET MAUI Blazor Hybrid apps
Creating a .NET MAUI Blazor project
Adding a shell and .NET MAUI pages
Creating a minimal API web service for categories
Configuring the .NET MAUI app to allow unsecure connections
Implementing the Model-View-ViewModel pattern
Getting categories from the web service
Integrating with native platforms
Working with the system clipboard
Picking files from the local filesystem
Enabling media and file picking on Windows
Enabling media and file picking on Android
Enabling media and file picking on iOS
Integrating with the media and file picker
Creating new windows
Getting device information
Enabling device information on Android
Adding device information to the app
Integrating with desktop menu bars
Popping up a toast notification
Using third-party control libraries
Practicing and exploring
Exercise 19.1 – Test your knowledge
Exercise 19.2 – Explore the code samples
Exercise 19.3 – Explore topics
Summary
Chapter 20: Introducing the Survey Project Challenge
What have you learned in this book?
Technologies covered in this book
Why a survey project?
What is the best way to learn?
Attributes of a good learning project
Alternative project ideas
Features of survey and polling tools
Question types
Polling and quizzes
Analyzing the responses
What are the product requirements?
Minimal requirements overview
Minimal website requirements
Minimal question item types
Minimal survey design requirements
Minimal data storage requirements
Minimal analysis app requirements
Ideas for extended requirements
Extended website requirements
Extended question item types
Extended survey design requirements
Extended data storage requirements
Extended analysis app requirements
Promote your abilities
Summary
Chapter 21: Epilogue
Second edition coming November 2023
Next steps on your C# and .NET learning journey
Good luck!
Index