Contents
Introduction 1
Version 1
Purpose 2
Who should use this guide 2
How you can use this guide 2
Characteristics of Modern Web Applications 3
Summary 3
Reference Application: eShopOnWeb 3
Cloud-Hosted and Scalable 4
Cross Platform 4
Modular and Loosely Coupled 5
Easily Tested with Automated Tests 5
Traditional and SPA Behaviors Supported 5
Simple Development and Deployment 6
Traditional ASP.NET and Web Forms 6
Choosing Between Traditional Web Apps and Single Page Apps (SPAs) 7
Summary 7
Razor Components 8
Project Templates 8
When to choose traditional web apps 11
When to choose SPAs 12
Decision table – Traditional Web or SPA 13
Architectural Principles 14
Summary 14
Common design principles 14
Separation of Concerns 14
Encapsulation 15
Dependency Inversion 15
Explicit Dependencies 17
Single Responsibility 17
Don’t Repeat Yourself (DRY) 18
Persistence Ignorance 19
Bounded Contexts 20
Common Web Application Architectures 21
Summary 21
What is a monolithic application? 21
All-in-One applications 21
What are layers? 22
Traditional “N-Layer” architecture applications 24
Clean architecture 28
Monolithic Applications and Containers 34
Monolithic application deployed as a container 36
Docker support 38
Common Client-Side Web Technologies 40
Summary 40
HTML 40
CSS 41
JavaScript 42
Legacy Web Apps with jQuery 42
jQuery vs a SPA Framework 42
Angular SPAs 43
React 44
Choosing a SPA Framework 44
Developing ASP.NET Core Apps 46
Summary 46
MVC and Razor Pages 46
Why Razor Pages? 47
When to use MVC 48
Mapping Requests to Responses 48
Working with Dependencies 51
Declare Your Dependencies 52
Structuring the Application 53
Feature Organization 54
Cross-Cutting Concerns 56
Security 59
Authentication 59
Authorization 61
Client Communication 64
Domain-Driven Design – Should You Apply It? 65
When Should You Apply DDD 66
When Shouldn’t You Apply DDD 66
Deployment 67
Working with Data in ASP.NET Core Apps 69
Summary 69
Entity Framework Core (for relational databases) 69
The DbContext 70
Configuring EF Core 70
Fetching and Storing Data 72
Fetching Related Data 73
Encapsulating Data 74
Resilient Connections 75
EF Core or micro-ORM? 77
SQL or NoSQL 79
Azure Cosmos DB 80
Other Persistence Options 81
Caching 81
ASP.NET Core Response Caching 81
Data Caching 82
Testing ASP.NET Core MVC Apps 86
Summary 86
Kinds of Automated Tests 86
Unit Tests 86
Integration Tests 87
Functional Tests 88
Testing Pyramid 89
What to Test 90
Organizing Test Projects 90
Test Naming 92
Unit Testing ASP.NET Core Apps 93
Integration Testing ASP.NET Core Apps 95
Functional Testing ASP.NET Core Apps 95
Development process for Azure-hosted ASP.NET Core applications 99
Vision 99
Development environment for ASP.NET Core apps 99
Development tools choices: IDE or editor 99
Development workflow for Azure-hosted ASP.NET Core apps 100
Initial Setup 100
Workflow for developing Azure-hosted ASP.NET Core applications 102
References 103
Azure Hosting Recommendations for ASP.NET Core Web Apps 104
Summary 104
Web Applications 104
App Service Web Apps 105
Azure Container Instances 105
Azure Kubernetes Service 105
Azure Service Fabric 106
Azure Virtual Machines 106
Logical Processes 107
Data 107
Architecture Recommendations 107