Professional C# 7 and .Net Core 2.0

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The professional's guide to C# 7, with expert guidance on the newest features

Professional C# 7 and .NET Core 2.0 provides experienced programmers with the information they need to work effectively with the world's leading programming language. The latest C# update added many new features that help you get more done in less time, and this book is your ideal guide for getting up to speed quickly. C# 7 focuses on data consumption, code simplification, and performance, with new support for local functions, tuple types, record types, pattern matching, non-nullable reference types, immutable types, and better support for variables. Improvements to Visual Studio will bring significant changes to the way C# developers interact with the space, bringing .NET to non-Microsoft platforms and incorporating tools from other platforms like Docker, Gulp, and NPM. Guided by a leading .NET expert and steeped in real-world practicality, this guide is designed to get you up to date and back to work.

With Microsoft speeding up its release cadence while offering more significant improvement with each update, it has never been more important to get a handle on new tools and features quickly. This book is designed to do just that, and more--everything you need to know about C# is right here, in the single-volume resource on every developer's shelf.

Tour the many new and enhanced features packed into C# 7 and .NET Core 2.0 Learn how the latest Visual Studio update makes developers' jobs easier Streamline your workflow with a new focus on code simplification and performance enhancement Delve into improvements made for localization, networking, diagnostics, deployments, and more Whether you're entirely new to C# or just transitioning to C# 7, having a solid grasp of the latest features allows you to exploit the language's full functionality to create robust, high -quality apps. Professional C# 7 and .NET Core 2.0 is the one-stop guide to everything you need to know.

Author(s): Christian Nagel
Publisher: Wrox Press
Year: 2018

Language: English
Pages: 1440

Cover
Title Page
Copyright
About the Author
About the Technical Editor
Credits
Acknowledgments
Contents
Introduction
The World of .NET Core
The World of C#
What’s New In C# 7
Digit Separators
Binary Literals
Expression-Bodied Members
Out Var
Non-Trailing Named Arguments
Readonly Struct
In Parameters
Private Protected
Target-Typed Default
Local Functions
Tuples
Inferred Tuple Names
Deconstructors
Pattern Matching
Throw Expressions
Async Main
Reference Semantics
What’s New in ASP.NET Core
What’s New With the Universal Windows Platform
What you Need to Write and Run C# Code
What This Book Covers
Part I: The C# Language
Part II: .NET Core and the Windows Runtime
Part III: Web Applications and Services
Part IV: Apps
Bonus Chapters
Conventions
Source Code
GitHub
Errata
Part I: The C# Language
Chapter 1: .NET Applications and Tools
Choosing Your Technologies
Reviewing .NET History
C# 1.0—A New Language
C# 2 and .NET 2 with Generics
.NET 3—Windows Presentation Foundation
C# 3 and .NET 3.5—LINQ
C# 4 and .NET 4—Dynamic and TPL
C# 5 and Asynchronous Programming
C# 6 and .NET Core 1.0
C# 7 and .NET Core 2.0
Choosing Technologies and Going Forward
.NET Terms
.NET Framework
.NET Core
.NET Standard
NuGet Packages
Namespaces
Common Language Runtime
Windows Runtime
Using the .NET Core CLI
Setting Up the Environment
Creating the Application
Building the Application
Running the Application
Creating a Web Application
Publishing the Application
Self-Contained Deployments
Using Visual Studio 2017
Installing Visual Studio 2017
Creating a Project
Working with Solution Explorer
Configuring Project Properties
Getting to Know the Editor
Building a Project
Running an Application
Debugging
Application Types and Technologies
Data Access
Windows Apps
Xamarin
Web Applications
Web API
WebHooks and SignalR
Microsoft Azure
Software as a Service
Infrastructure as a Service
Platform as a Service
Functions as a Service
Developer Tools
Visual Studio Community
Visual Studio Professional
Visual Studio Enterprise
Visual Studio for Mac
Visual Studio Code
Summary
Chapter 2: Core C#
Fundamentals of C#
Hello, World!
Working with Variables
Initializing Variables
Using Type Inference
Understanding Variable Scope
Scope Clashes for Local Variables
Scope Clashes for Fields and Local Variables
Working with Constants
Using Predefined Data Types
Value Types and Reference Types
.NET Types
Predefined Value Types
Integer Types
Digit Separators
Working with Binary Values
Floating-Point Types
The Decimal Type
The Boolean Type
The Character Type
Literals for Numbers
Predefined Reference Types
The object Type
The string Type
Controlling Program Flow
Conditional Statements
The if Statement
The switch Statement
Loops
The for Loop
The while Loop
The do. . .while Loop
The foreach Loop
Jump Statements
The goto Statement
The break Statement
The continue Statement
The return Statement
Getting Organized with Namespaces
The using Directive
Namespace Aliases
Understanding the Main Method
Using Comments
Internal Comments Within the Source Files
XML Documentation
Understanding C# Preprocessor Directives
#define and #undef
#if, #elif, #else, and #endif
#warning and #error
#region and #endregion
#line
#pragma
C# Programming Guidelines
Rules for Identifiers
Usage Conventions
Naming Conventions
Casing of Names
Name Styles
Namespace Names
Names and Keywords
Use of Properties and Methods
Use of Fields
Summary
Chapter 3: Objects and Types
Creating and Using Classes
Classes and Structs
Classes
Fields
Readonly Fields
Properties
Expression-Bodied Property Accessors
Auto-Implemented Properties
Access Modifiers for Properties
Read-Only Properties
Auto-Implemented Read-Only Properties
Expression-Bodied Properties
Immutable Types
Anonymous Types
Methods
Declaring Methods
Expression-Bodied Methods
Invoking Methods
Method Overloading
Named Arguments
Optional Arguments
Variable Number of Arguments
Constructors
Expression Bodies with Constructors
Calling Constructors from Other Constructors
Static Constructors
Structs
Structs Are Value Types
Readonly structs
Structs and Inheritance
Constructors for Structs
ref structs
Passing Parameters by Value and by Reference
ref Parameters
out Parameters
in Parameters
Nullable Types
Enum Types
Partial Classes
Extension Methods
The Object Class
Summary
Chapter 4: Object-Oriented Programming with C#
Object Orientation
Types of Inheritance
Multiple Inheritance
Structs and Classes
Implementation Inheritance
Virtual Methods
Polymorphism
Hiding Methods
Calling Base Versions of Methods
Abstract Classes and Methods
Sealed Classes and Methods
Constructors of Derived Classes
Modifiers
Access Modifiers
Other Modifiers
Interfaces
Defining and Implementing Interfaces
Interface Inheritance
Is and as Operators
Summary
Chapter 5: Generics
Generics Overview
Performance
Type Safety
Binary Code Reuse
Code Bloat
Naming Guidelines
Creating Generic Classes
Generics Features
Default Values
Constraints
Inheritance
Static Members
Generic Interfaces
Covariance and Contra-Variance
Covariance with Generic Interfaces
Contra-Variance with Generic Interfaces
Generic Structs
Generic Methods
Generic Methods Example
Generic Methods with Constraints
Generic Methods with Delegates
Generic Methods Specialization
Summary
Chapter 6: Operators and Casts
Operators and Casts
Operators
Operator Shortcuts
The Conditional-Expression Operator (?:)
The checked and unchecked Operators
The is Operator
The as Operator
The sizeof Operator
The typeof Operator
The nameof Operator
The index Operator
Nullable Types and Operators
The Null Coalescing Operator
The Null-Conditional Operator
Operator Precedence and Associativity
Using Binary Operators
Shifting Bits
Signed and Unsigned Numbers
Type Safety
Type Conversions
Implicit Conversions
Explicit Conversions
Boxing and Unboxing
Comparing Objects for Equality
Comparing Reference Types for Equality
The ReferenceEquals Method
The Virtual Equals Method
The Static Equals Method
Comparison Operator (==)
Comparing Value Types for Equality
Operator Overloading
How Operators Work
Operator Overloading Example: The struct Vector
Overloading the Comparison Operators
Which Operators Can You Overload?
Implementing Custom Index Operators
User-Defined Casts
Implementing User-Defined Casts
Casts Between Classes
Casts Between Base and Derived Classes
Boxing and Unboxing Casts
Multiple Casting
Summary
Chapter 7: Arrays
Multiple Objects of the Same Type
Simple Arrays
Array Declaration
Array Initialization
Accessing Array Elements
Using Reference Types
Multidimensional Arrays
Jagged Arrays
Array Class
Creating Arrays
Copying Arrays
Sorting
Arrays as Parameters
Array Covariance
Enumerators
IEnumerator Interface
foreach Statement
yield Statement
Different Ways to Iterate Through Collections
Returning Enumerators with Yield Return
Structural Comparison
Spans
Creating Slices
Changing Values Using Spans
ReadOnly Spans
Array Pools
Creating the Array Pool
Renting Memory from the Pool
Returning Memory to the Pool
Summary
Chapter 8: Delegates, Lambdas, and Events
Referencing Methods
Delegates
Declaring Delegates
Using Delegates
Simple Delegate Example
Action and Func Delegates
BubbleSorter Example
Multicast Delegates
Anonymous Methods
Lambda Expressions
Parameters
Multiple Code Lines
Closures
Events
Event Publisher
Event Listener
Summary
Chapter 9: Strings and Regular Expressions
Examining System.String
Building Strings
StringBuilder Members
String Formats
String Interpolation
FormattableString
Using Other Cultures with String Interpolation
Escaping Curly Brackets
DateTime and Number Formats
Custom String Formats
Regular Expressions
Introduction to Regular Expressions
The RegularExpressionsPlayground Example
Displaying Results
Matches, Groups, and Captures
Strings and Spans
Summary
Chapter 10: Collections
Overview
Collection Interfaces and Types
Lists
Creating Lists
Collection Initializers
Adding Elements
Inserting Elements
Accessing Elements
Removing Elements
Searching
Sorting
Read-Only Collections
Queues
Stacks
Linked Lists
Sorted List
Dictionaries
Dictionary Initializers
Key Type
Dictionary Example
Lookups
Sorted Dictionaries
Sets
Performance
Summary
Chapter 11: Special Collections
Overview
Working with Bits
BitArray
BitVector32
Observable Collections
Immutable Collections
Using Builders with Immutable Collections
Immutable Collection Types and Interfaces
Using LINQ with Immutable Arrays
Concurrent Collections
Creating Pipelines
Using a BlockingCollection
Using a ConcurrentDictionary
Completing the Pipeline
Summary
Chapter 12: Language Integrated Query
LINQ Overview
Lists and Entities
LINQ Query
Extension Methods
Deferred Query Execution
Standard Query Operators
Filtering
Filtering with Index
Type Filtering
Compound from
Sorting
Grouping
Variables Within the LINQ Query
Grouping with Nested Objects
Inner Join
Left Outer Join
Group Join
Set Operations
Zip
Partitioning
Aggregate Operators
Conversion Operators
Generation Operators
Parallel LINQ
Parallel Queries
Partitioners
Cancellation
Expression Trees
LINQ Providers
Summary
Chapter 13: Functional Programming with C#
What Is Functional Programming?
Avoiding State Mutation
Functions as First Class
Higher-Order Functions
Pure Functions
Expression-Bodied Members
Extension Methods
Using Static
Local Functions
Local Functions with the yield Statement
Recursive Local Functions
Tuples
Declaring and Initializing Tuples
Tuple Deconstruction
Returning Tuples
Behind the Scenes
Compatibility of ValueTuple with Tuple
Infer Tuple Names
Tuples with Linked Lists
Tuples with LINQ
Deconstruction
Deconstruction with Extension Methods
Pattern Matching
Pattern Matching with the is Operator
Pattern Matching with the switch Statement
Pattern Matching with Generics
Summary
Chapter 14: Errors and Exceptions
Introduction
Exception Classes
Catching Exceptions
Exceptions and Performance
Implementing Multiple Catch Blocks
Catching Exceptions from Other Code
System.Exception Properties
Exception Filters
Re-throwing Exceptions
Naïve Use to Rethrow the Exception
Changing the Exception
Rethrowing the Exception
Using Filters to Add Functionality
What Happens If an Exception Isn’t Handled?
User-Defined Exception Classes
Catching the User-Defined Exceptions
Throwing the User-Defined Exceptions
Defining the User-Defined Exception Classes
Caller Information
Summary
Chapter 15: Asynchronous Programming
Why Asynchronous Programming Is Important
.NET History of Asynchronous Programming
Synchronous Call
Asynchronous Pattern
Event-Based Asynchronous Pattern
Task-Based Asynchronous Pattern
Async Main Method
Foundation of Asynchronous Programming
Creating Tasks
Calling an Asynchronous Method
Using the Awaiter
Continuation with Tasks
Synchronization Context
Using Multiple Asynchronous Methods
Calling Asynchronous Methods Sequentially
Using Combinators
Using ValueTasks
Converting the Asynchronous Pattern
Error Handling
Handling Exceptions with Asynchronous Methods
Handling Exceptions with Multiple Asynchronous Methods
Using AggregateException Information
Async with Windows Apps
Configure Await
Switch to the UI Thread
Using IAsyncOperation
Avoid Blocking Scenarios
Summary
Chapter 16: Reflection, Metadata, and Dynamic Programming
Inspecting Code at Runtime and Dynamic Programming
Custom Attributes
Writing Custom Attributes
Specifying the AttributeUsage Attribute
Specifying Attribute Parameters
Specifying Optional Attribute Parameters
Custom Attribute Example: WhatsNewAttributes
The WhatsNewAttributes Library
The VectorClass Library
Using Reflection
The System.Type Class
Type Properties
Methods
The TypeView Example
The Assembly Class
Getting Details About Types Defined in an Assembly
Getting Details About Custom Attributes
Completing the WhatsNewAttributes Example
Using Dynamic Language Extensions for Reflection
Creating the Calculator Library
Instantiating a Type Dynamically
Invoking a Member with the Reflection API
Invoking a Member with the Dynamic Type
The Dynamic Type
Dynamic Behind the Scenes
DynamicObject and ExpandoObject
DynamicObject
ExpandoObject
Summary
Chapter 17: Managed and Unmanaged Memory
Memory
Memory Management Under the Hood
Value Data Types
Reference Data Types
Garbage Collection
Strong and Weak References
Working with Unmanaged Resources
Destructors or Finalizers
The IDisposable Interface
The using Statement
Implementing IDisposable and a Destructor
IDisposable and Finalizer Rules
Unsafe Code
Accessing Memory Directly with Pointers
Writing Unsafe Code with the unsafe Keyword
Pointer Syntax
Casting Pointers to Integer Types
Casting Between Pointer Types
void Pointers
Pointer Arithmetic
The sizeof Operator
Pointers to Structs: The Pointer Member Access Operator
Pointers to Class Members
Pointer Example: PointerPlayground
Using Pointers to Optimize Performance
Creating Stack-Based Arrays
QuickArray Example
Reference Semantics
Passing ref and returning ref
Ref and Arrays
Span
Spans Referencing the Managed Heap
Spans Referencing the Stack
Spans Referencing the Native Heap
Span Extension Methods
Platform Invoke
Summary
Chapter 18: Visual Studio 2017
Working with Visual Studio 2017
Visual Studio Editions
Visual Studio Settings
Creating a Project
Multi-Targeting .NET
Selecting a Project Type
Using Windows Universal Project Templates
Using .NET Core Project Templates
Using .NET Standard Templates
Exploring and Coding a Project
Solution Explorer
Working with Projects and Solutions
Adding Projects to a Solution
Setting the Startup Project
Discovering Types and Members
Previewing Items
Using Scopes
Adding Items to a Project
Managing References and Dependencies
Working with the Code Editor
The Folding Editor
Navigating Within the Editor
IntelliSense
CodeLens
Using Code Snippets
EditorConfig
Learning and Understanding Other Windows
Using the Design View Window
Using the Properties Window
Using the Class View Window
Using the Object Browser Window
Using the Server Explorer Window
Using the Cloud Explorer
Using the Document Outline
Arranging Windows
Building a Project
Building, Compiling, and Making Code
Debugging and Release Builds
Optimization
Debugger Symbols
Extra Source Code Debugging Commands
Selecting a Configuration
Editing Configurations
Debugging Your Code
Setting Breakpoints
Using Data Tips and Debugger Visualizers
Live Visual Tree
Monitoring and Changing Variables
Exceptions
Multithreading
Refactoring Tools
Diagnostic Tools
Creating and Using Containers with Docker
Hello Docker!
Running ASP.NET Core in a Docker Container
Creating a Dockerfile
Using Visual Studio
Summary
Part II: .NET Core and the Windows Runtime
Chapter 19: Libraries, Assemblies, Packages, and NuGet
The Hell of Libraries
Assemblies
Creating Libraries
.NET Standard
Creating a .NET Standard Library
Solution Files
Referencing Projects
Referencing NuGet Packages
NuGet Sources
Using .NET Framework Libraries
Using Shared Projects
Creating NuGet Packages
NuGet Packages with the Command Line
Supporting Multiple Platforms
NuGet Packages with Visual Studio
Summary
Chapter 20: Dependency Injection
What Is Dependency Injection?
Using a Service Without Dependency Injection
Using Dependency Injection
Using the .NET Core DI Container
Lifetime of Services
Using Singleton and Transient Services
Using Scoped Services
Using Custom Factories
Initialization of Services Using Options
Using Configuration Files
Creating Platform Independence
.NET Standard Library
WPF Application
UWP Application
Xamarin Application
Using Other DI Containers
Summary
Chapter 21: Tasks and Parallel Programming
Overview
Parallel Class
Looping with the Parallel.For Method
Stopping Parallel.For Early
Parallel For Initialization
Looping with the Parallel.ForEach Method
Invoking Multiple Methods with the Parallel.Invoke Method
Tasks
Starting Tasks
Tasks Using the Thread Pool
Synchronous Tasks
Tasks Using a Separate Thread
Futures—Results from Tasks
Continuation Tasks
Task Hierarchies
Returning Tasks from Methods
Waiting for Tasks
Value Tasks
Cancellation Framework
Cancellation of Parallel.For
Cancellation of Tasks
Data Flow
Using an Action Block
Source and Target Blocks
Connecting Blocks
Timers
Threading Issues
Race Conditions
Deadlocks
The lock Statement and Thread Safety
Interlocked
Monitor
SpinLock
WaitHandle
Mutex
Semaphore
Events
Barrier
ReaderWriterLockSlim
Locks with Await
Summary
Chapter 22: Files and Streams
Introduction
Managing the File System
Checking Drive Information
Working with the Path Class
Creating Files and Folders
Accessing and Modifying File Properties
Using File to Read and Write
Enumerating Files
Working with Streams
Working with File Streams
Creating a FileStream
Getting Stream Information
Analyzing Text File Encodings
Reading Streams
Writing Streams
Copying Streams
Using Random Access to Streams
Using Buffered Streams
Using Readers and Writers
The StreamReader Class
The StreamWriter Class
Reading and Writing Binary Files
Compressing Files
Using the Deflate Stream
Using Brotli
Zipping Files
Watching File Changes
Working with Memory Mapped Files
Using Accessors to Create Memory Mapped Files
Using Streams to Create Memory Mapped Files
Communicating with Pipes
Creating a Named Pipe Server
Creating a Named Pipe Client
Creating Anonymous Pipes
Using Files and Streams with the Windows Runtime
Windows App Editor
Mapping Windows Runtime Types to .NET Types
Summary
Chapter 23: Networking
Networking
The HttpClient Class
Making an Asynchronous Get Request
Throwing Exceptions
Passing Headers
Accessing the Content
Customizing Requests with HttpMessageHandler
Creating an HttpRequestMessage Using SendAsync
Using HttpClient with Windows Runtime
Working with the WebListener Class
Working with Utility Classes
URIs
IPAddress
IPHostEntry
Dns
Using TCP
Creating an HTTP Client Using TCP
Creating a TCP Listener
Creating a TCP Client
TCP Versus UDP
Using UDP
Building a UDP Receiver
Creating a UDP Sender
Using Multicasts
Using Sockets
Creating a Listener Using Sockets
Using NetworkStream with Sockets
Using Readers and Writers with Sockets
Implementing a Receiver Using Sockets
Summary
Chapter 24: Security
Introduction
Verifying User Information
Working with Windows Identities
Windows Principals
Using Claims
Encrypting Data
Creating and Verifying a Signature
Implementing Secure Data Exchange
Signing and Hashing Using RSA
Protecting Data
Implementing Data Protection
User Secrets
Access Control to Resources
Web Security
Encoding
SQL Injection
Cross-Site Request Forgery
Summary
Chapter 25: ADO.NET and Transactions
ADO.NET Overview
Sample Database
NuGet Packages and Namespaces
Using Database Connections
Managing Connection Strings
Connection Pools
Connection Information
Commands
ExecuteNonQuery
ExecuteScalar
ExecuteReader
Calling Stored Procedures
Asynchronous Data Access
Transactions with ADO.NET
Transactions with System.Transactions
Committable Transactions
Dependent Transactions
Ambient Transactions
Nested Scopes with Ambient Transactions
Summary
Chapter 26: Entity Framework Core
History of Entity Framework
Introducing EF Core
Creating a Model
Conventions, Annotations, and Fluent API
Creating a Context
Creating the Database
Deleting the Database
Writing to the Database
Reading from the Database
Updating Records
Deleting Records
Logging
Using Dependency Injection
Creating a Model
Creating a Relation
Data Annotations
Fluent API
Self-Contained Type Configuration
Scaffolding a Model from the Database
Mapping to Fields
Shadow Properties
Queries
Basic Queries
Client and Server Evaluation
Raw SQL Queries
Compiled Queries
Global Query Filters
EF.Functions
Relationships
Relationships Using Conventions
Explicit Loading Related Data
Eager Loading Related Data
Relationships Using Annotations
Relationships Using Fluent API
Table per Hierarchy with Conventions
Table per Hierarchy with Fluent API
Table Splitting
Owned Entities
Saving Data
Adding Objects with Relations
Object Tracking
Updating Objects
Updating Untracked Objects
Batching
Conflict Handling
The Last One Wins
The First One Wins
Context Pooling
Using Transactions
Using Implicit Transactions
Creating Explicit Transactions
Migrations
Preparing the Project File
Hosting Applications with ASP.NET Core MVC
Hosting .NET Core Console App
Creating Migrations
Applying Migrations Programmatically
Other Ways to Apply Migrations
Summary
Chapter 27: Localization
Global Markets
Namespace System.Globalization
Unicode Issues
Cultures and Regions
Specific, Neutral, and Invariant Cultures
Current Culture and CurrentUICulture
Number Formatting
Date Formatting
Cultures in Action
Sorting
Resources
Resource Readers and Writers
Using the Resource File Generator
Using Resource Files with ResourceManager
The System.Resources Namespace
Localization with ASP.NET Core
Registering Localization Services
Injecting Localization Services
Culture Providers
Using Resources from ASP.NET Core
Localizing with Controllers and Views
Localization with the Universal Windows Platform
Using Resources with UWP
Localization with the Multilingual App Toolkit
Summary
Chapter 28: Testing
Overview
Unit Testing with MSTest
Creating Unit Tests with MSTest
Running Unit Tests
Expecting Exceptions with MSTest
Testing All Code Paths
External Dependencies
Unit Testing with xUnit
Using xUnit with .NET Core
Creating Facts
Creating Theories
Using a Mocking Library
Live Unit Testing
Unit Testing with EF Core
UI Testing with Windows Apps
Web Integration, Load, and Performance Testing
ASP.NET Core Integration Tests
Creating the Web Test
Running the Web Test
Summary
Chapter 29: Tracing, Logging, and Analytics
Diagnostics Overview
Tracing with EventSource
Examining a Simple Use of EventSource
Understanding Tools for Tracing
Logman
Tracerpt
PerfView
Deriving from EventSource
Using Annotations with EventSource
Creating Event Manifest Schema
Using Activity IDs
Creating Custom Listeners
Writing Logs with the ILogger Interface
Configuring Providers
Using Scopes
Filtering
Configure Logging
Using ILogger Without Dependency Injection
Analytics with Visual Studio App Center
Summary
Part III: Web Applications And Services
Chapter 30: ASP.NET Core
ASP.NET Core
Web Technologies
HTML
CSS
JavaScript and TypeScript
Scripting Libraries
ASP.NET Web Project
Startup
Sample Application
Adding Client-Side Content
Using Tools for Client Content
Using Client-Side Libraries with Bower
Using a JavaScript Package Manager: npm
Bundling
Packaging with webpack
Request and Response
Request Headers
Query String
Encoding
Form Data
Cookies
Sending JSON
Dependency Injection
Defining a Service
Registering the Service
Injecting the Service
Calling the Controller
Simple Routing
Creating Custom Middleware
Session State
Configuring with ASP.NET Core
Reading the Configuration
Changing Configuration Providers
Different Configurations Based on the Environment
Summary
Chapter 31: ASP.NET Core MVC
Setting Up Services for ASP.NET Core MVC
Defining Routes
Adding Routes
Using Route Constraints
Creating Controllers
Understanding Action Methods
Using Parameters
Returning Data
Working with the Controller Base Class and POCO Controllers
Creating Views
Passing Data to Views
Understanding Razor Syntax
Creating Strongly Typed Views
Defining the Layout
Using a Default Layout Page
Using Sections
Defining Content with Partial Views
Using Partial Views from Server-Side Code
Returning Partial Views from the Controller
Working with View Components
Using Dependency Injection in Views
Importing Namespaces with Multiple Views
Receiving Data from the Client
Model Binder
Annotations and Validation
Working with HTML Helpers
Using Simple Helpers
Using Model Data
Defining HTML Attributes
Creating Lists
Using Strongly Typed Helpers
Working with Editor Extensions
Implementing Templates
Getting to Know Tag Helpers
Activating Tag Helpers
Using Anchor Tag Helpers
Using Label Tag Helpers
Using Input Tag Helpers
Using a Form with Validation
Environment Tag Helper
Creating Custom Tag Helpers
Creating Elements with Tag Helpers
Implementing Action Filters
Creating a Data-Driven Application
Defining a Model
Creating a Database
Creating a Service
Creating a Controller
Creating Views
Implementing Authentication and Authorization
Storing and Retrieving User Information
Starting Up the Identity System
Performing User Registration
Setting Up User Login
Authenticating Users
Authenticating Users with Azure Active Directory
Creating the Azure Active Directory B2C Tenant
Creating the ASP.NET Core Web Application with Azure AD B2C
Razor Pages
Creating a Razor Pages Project
Implementing Data Access
Using Inline Code
Using Inline Code with a Page Model
Using Code-Behind
Page Parameters
Summary
Chapter 32: Web API
Overview
Creating Services
Defining a Model
Creating a Service
Creating a Controller
Changing the Response Format
REST Results and Status Codes
Creating an Async Service
Creating a .NET Client
Sending GET Requests
Receiving XML from the Service
Sending POST Requests
Sending PUT Requests
Sending DELETE Requests
Writing to the Database
Using EF Core
Creating the Data Access Service
Creating Metadata with the OpenAPI or Swagger
Creating and Using OData Services
Creating a Data Model
Creating the Database
OData Startup Code
Creating the OData Controller
OData Query
Using Azure Functions
Creating Azure Functions
Using a Dependency Injection Container
Implementing GET, POST, and PUT Requests
Running the Azure Function
Summary
Part IV: Apps
Chapter 33: Windows Apps
Introducing Windows Apps
Windows Runtime
Hello, Windows
Application Manifest
Application Startup
Main Page
Intro to XAML
XAML Standard
Mapping Elements to Classes
Using Custom .NET Classes with XAML
Setting Properties as Attributes
Using Properties as Elements
Dependency Properties
Creating a Dependency Property
Value Changed Callbacks and Events
Routed Events
Attached Properties
Markup Extensions
Custom Markup Extensions
Conditional XAML
Controls
Framework-Derived UI Elements
Presenters
Parallax
Control-Derived Controls
Using a TextBox
Selecting a Date
Range Controls
Progress Bar
Slider
Content Controls
Buttons
Replacing the Content of the Button
Linking with the HyperlinkButton
Items Controls
Flyouts
Data Binding
Change Notification with INotifyPropertyChanged
Creating a List of Books
List Binding
Binding Events to Methods
Using Data Templates and the Data Template Selector
Binding Simple Objects
Value Conversion
Navigation
Navigating to the Initial Page
Overriding Page Class Navigation
Navigating Between Pages
Back Button
Hub
Pivot
NavigationView
Layout Panels
StackPanel
Canvas
Grid
VariableSizedWrapGrid
RelativePanel
Adaptive Triggers
XAML Views
Deferred Loading
Summary
Chapter 34: Patterns with XAML Apps
Why MVVM?
Defining the MVVM Pattern
Sharing Code
Using API Contracts with the Universal Windows Platform
Working with Shared Projects
Working with .NET Standard Libraries
Sample Solution
Models
Implementing Change Notification
Using the Repository Pattern
Services
View Models
Using IEditableObject
Concrete View Model Implementations
Commands
Services, ViewModels, and Dependency Injection
Views
Opening Dialogs from View Models
Navigation Between Pages
Adaptive User Interfaces
Showing Progress Information
Using Actions in List Items
Messaging Using Events
Using a Framework
Summary
Chapter 35: Styling Windows Apps
Styling
Shapes
Geometry
Geometries Using Segments
Geometries Using Path Markup
Transformation
Scaling
Translating
Rotating
Skewing
Transforming with Groups and Composite Transforms
Transforming Using a Matrix
Brushes
SolidColorBrush
LinearGradientBrush
ImageBrush
AcrylicBrush
Reveal Brushes
Styles and Resources
Styles
Resources
Accessing Resources from Code
Resource Dictionaries
Theme Resources
Defining Theme Resources
Selecting a Theme
Templates
Control Templates
Data Templates
Styling a ListView
DataTemplate for ListView Items
Item Container Style
Items Panel
List View Control Template
Animations
Timeline
Easing Functions
Keyframe Animations
Transitions
Reposition Transition
Pane Transition
Transitions for Items
Visual State Manager
Predefined States with Control Templates
Defining Custom States
Setting Custom States
Summary
Chapter 36: Advanced Windows Apps
Overview
App Lifetime
Application Execution States
Navigation Between Pages
Navigation State
Suspending the App
Activating the App from Suspension
Testing Suspension
Page State
Sharing Data
Sharing Source
Sharing Target
App Services
Creating the Model
Creating a Background Task for App Service Connections
Registering the App Service
Calling the App Service
Advanced Compiled Binding
Compiled Data Binding Lifetime
Binding to Methods
Phasing with x:Bind
Using Text
Using Fonts
Inline and Block Elements
Using Overflow Areas
Inking
AutoSuggest
Summary
Chapter 37: Xamarin.Forms
Starting with Xamarin Development
Architecture Xamarin with Android
Architecture Xamarin with iOS
Xamarin.Forms
Tools for Xamarin Development
Android
iOS
Visual Studio 2017
Visual Studio for Mac
Visual Studio App Center
Android Foundation
Activity
Resources
Displaying Lists
Defining a Model
Using the ListActivity
Implementing an Adapter
Navigation with Android
Showing a Message
iOS Foundation
iOS App Structure
Storyboard
Controller
Showing a Message
Xamarin.Forms Application
Windows Apps Hosting Xamarin
Android Hosting Xamarin
iOS Hosting Xamarin
Shared Project
Using the Common Libraries
Control Hierarchy
Pages
Navigation
Layout
Views
Data Binding
Commands
ListView and ViewCell
Summary
Index
EULA