Book title
Book subtitle
Author Name
PUBLISHED BY
DevDiv, .NET and Visual Studio product teams
A division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright © 2017 by Microsoft Corporation
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.
This book is provided "as-is" and expresses the author's views and opinions. The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice.
Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred.
Microsoft and the trademarks listed at http://www.microsoft.com on the "Trademarks" webpage are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.
Author: David Britch
Developer: Javier Suarez Ruiz (Plain Concepts)
Participants and reviewers: Craig Dunn, Tom Opgenorth
Editor: John Meade (Populus Group)
Contents
Preface iv
Purpose iv
What's left out of this guide's scope iv
Who should use this guide iv
How to use this guide v
Introduction 1
Sample application 2
Sample application architecture 2
Mobile app 4
eShopOnContainers.Core project 5
Platform projects 6
Summary 6
MVVM 7
The MVVM pattern 7
View 8
ViewModel 8
Model 9
Connecting view models to views 9
Creating a view model declaratively 10
Creating a view model programmatically 10
Creating a view defined as a data template 10
Automatically creating a view model with a view model locator 11
Updating views in response to changes in the underlying view model or model 12
UI interaction using commands and behaviors 13
Implementing commands 13
Implementing behaviors 15
Summary 17
Dependency injection 18
Introduction to dependency injection 18
Registration 20
Resolution 21
Managing the lifetime of resolved objects 22
Summary 23
Communicating between loosely coupled components 24
Introduction to MessagingCenter 24
Defining a message 26
Publishing a message 26
Subscribing to a message 27
Unsubscribing from a message 27
Summary 27
Navigation 28
Navigating between pages 29
Creating the NavigationService instance 29
Handling navigation requests 30
Navigating when the app is launched 32
Passing parameters during navigation 33
Invoking navigation using behaviors 34
Confirming or cancelling navigation 34
Summary 34
Validation 35
Specifying validation rules 36
Adding validation rules to a property 37
Triggering validation 38
Triggering validation manually 38
Triggering validation when properties change 39
Displaying validation errors 39
Highlighting a control that contains invalid data 40
Displaying error messages 43
Summary 44
Configuration management 45
Creating a settings class 45
Adding a setting 46
Data binding to user settings 47
Summary 49
Containerized microservices 50
Microservices 51
Containerization 52
Communication between client and microservices 54
Communication between microservices 55
Summary 57
Authentication and authorization 58
Authentication 58
Issuing bearer tokens using IdentityServer 4 59
Adding IdentityServer to a web application 59
Configuring IdentityServer 60
Performing authentication 63
Authorization 68
Configuring IdentityServer to perform authorization 69
Making access requests to APIs 69
Summary 70
Accessing remote data 71
Introduction to Representational State Transfer 71
Consuming RESTful APIs 72
Making web requests 72
Caching data 79
Managing data expiration 80
Caching images 80
Increasing resilience 81
Retry pattern 81
Circuit breaker pattern 82
Summary 83
Unit testing 84
Dependency injection and unit testing 84
Testing MVVM applications 85
Testing asynchronous functionality 86
Testing INotifyPropertyChanged implementations 86
Testing message-based communication 87
Testing exception handling 87
Testing validation 88
Summary 89