Architect Modern Web Applications With Aspnet
Core And Azure 501 Steve Ardalis Smith download
https://ebookbell.com/product/architect-modern-web-applications-
with-aspnet-core-and-azure-501-steve-ardalis-smith-36510892
Explore and download more ebooks at ebookbell.com
Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Architect Modern Web Applications With Aspnet Core And Azure V60
20211217 Steve Ardalis Smith
https://ebookbell.com/product/architect-modern-web-applications-with-
aspnet-core-and-azure-v60-20211217-steve-ardalis-smith-46619716
Architect Modern Web Applications With Aspnet Core And Azure V70 Steve
Ardalis Smith
https://ebookbell.com/product/architect-modern-web-applications-with-
aspnet-core-and-azure-v70-steve-ardalis-smith-54560582
Architect Modern Web Applications With Aspnet Core And Azure V50 Steve
Ardalis Smith
https://ebookbell.com/product/architect-modern-web-applications-with-
aspnet-core-and-azure-v50-steve-ardalis-smith-35158112
Generative Ai For Cloud Solutions Architect Modern Ai Llms In Secure
Scalable And Ethical Cloud Environments Paul Singh Anurag Karuparti
https://ebookbell.com/product/generative-ai-for-cloud-solutions-
architect-modern-ai-llms-in-secure-scalable-and-ethical-cloud-
environments-paul-singh-anurag-karuparti-56834956
Vp Menon The Unsung Architect Of Modern India Narayani Basu
https://ebookbell.com/product/vp-menon-the-unsung-architect-of-modern-
india-narayani-basu-10989064
Karl Langer Modern Architect And Migrant In The Australian Tropics
Deborah Van Der Plaat
https://ebookbell.com/product/karl-langer-modern-architect-and-
migrant-in-the-australian-tropics-deborah-van-der-plaat-50233500
Ernesto Nathan Rogers The Modern Architect As Public Intellectual
Maurizio Sabini
https://ebookbell.com/product/ernesto-nathan-rogers-the-modern-
architect-as-public-intellectual-maurizio-sabini-50216376
The Man In The Glass House Philip Johnson Architect Of The Modern
Century Mark Lamster
https://ebookbell.com/product/the-man-in-the-glass-house-philip-
johnson-architect-of-the-modern-century-mark-lamster-51456300
Rpa Solution Architects Handbook Design Modern And Custom Rpa
Solutions For Digital Innovation 1st Edition Sachin Sahgal
https://ebookbell.com/product/rpa-solution-architects-handbook-design-
modern-and-custom-rpa-solutions-for-digital-innovation-1st-edition-
sachin-sahgal-50482364
EDITION v5.0.1 - Updated to ASP.NET Core 5.0
Refer changelog for the book updates and community contributions.
PUBLISHED BY
Microsoft Developer Division, .NET, and Visual Studio product teams
A division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright © 2021 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 https://www.microsoft.com on the “Trademarks” webpage are
trademarks of the Microsoft group of companies.
Mac and macOS are trademarks of Apple Inc.
The Docker whale logo is a registered trademark of Docker, Inc. Used by permission.
All other marks and logos are property of their respective owners.
Author:
Steve “ardalis” Smith - Software Architect and Trainer - Ardalis.com
Editors:
Maira Wenzel
Action links
• This e-book is also available in a PDF format (English version only) Download
• Clone/Fork the reference application eShopOnWeb on GitHub
Introduction
.NET 5 and ASP.NET Core offer several advantages over traditional .NET development. You should use
.NET 5 for your server applications if some or all of the following are important to your application’s
success:
• Cross-platform support.
• Use of microservices.
• Use of Docker containers.
• High performance and scalability requirements.
• Side-by-side versioning of .NET versions by application on the same server.
Traditional .NET applications can and do support many of these requirements, but ASP.NET Core and
.NET 5 have been optimized to offer improved support for the above scenarios.
More and more organizations are choosing to host their web applications in the cloud using services
like Microsoft Azure. You should consider hosting your application in the cloud if the following are
important to your application or organization:
• Reduced investment in data center costs (hardware, software, space, utilities, server
management, etc.)
• Flexible pricing (pay based on usage, not for idle capacity).
• Extreme reliability.
• Improved app mobility; easily change where and how your app is deployed.
• Flexible capacity; scale up or down based on actual needs.
Building web applications with ASP.NET Core, hosted in Azure, offers many competitive advantages
over traditional alternatives. ASP.NET Core is optimized for modern web application development
practices and cloud hosting scenarios. In this guide, you’ll learn how to architect your ASP.NET Core
applications to best take advantage of these capabilities.
Version
This guide has been revised to cover .NET 5.0 version along with many additional updates related to
the same “wave” of technologies (that is, Azure and additional third-party technologies) coinciding in
time with the .NET 5.0 release. That’s why the book version has also been updated to version 5.0.
Purpose
This guide provides end-to-end guidance on building monolithic web applications using ASP.NET
Core and Azure. In this context, “monolithic” refers to the fact that these applications are deployed as
a single unit, not as a collection of interacting services and applications.
This guide is complementary to “.NET Microservices. Architecture for Containerized .NET Applications”,
which focuses more on Docker, microservices, and deployment of containers to host enterprise
applications.
.NET Microservices. Architecture for Containerized .NET Applications
• e-book
https://aka.ms/MicroservicesEbook
• Sample Application
https://aka.ms/microservicesarchitecture
Who should use this guide
The audience for this guide is mainly developers, development leads, and architects who are
interested in building modern web applications using Microsoft technologies and services in the
cloud.
A secondary audience is technical decision makers who are already familiar ASP.NET or Azure and are
looking for information on whether it makes sense to upgrade to ASP.NET Core for new or existing
projects.
How you can use this guide
This guide has been condensed into a relatively small document that focuses on building web
applications with modern .NET technologies and Azure. As such, it can be read in its entirety to
provide a foundation of understanding such applications and their technical considerations. The
guide, along with its sample application, can also serve as a starting point or reference. Use the
associated sample application as a template for your own applications, or to see how you might
organize your application’s component parts. Refer back to the guide’s principles and coverage of
architecture and technology options and decision considerations when you’re weighing these choices
for your own application.
Feel free to forward this guide to your team to help ensure a common understanding of these
considerations and opportunities. Having everybody working from a common set of terminology and
underlying principles helps ensure consistent application of architectural patterns and practices.
References
• Choosing between .NET 5 and .NET Framework for server apps
https://docs.microsoft.com/dotnet/standard/choosing-core-framework-server
Contents
Characteristics of Modern Web Applications ....................................................................... 1
Reference application: eShopOnWeb .............................................................................................................................. 1
Reference Application ....................................................................................................................................................... 2
Cloud-hosted and scalable .................................................................................................................................................. 2
Cross platform ........................................................................................................................................................................... 2
Modular and loosely coupled ............................................................................................................................................. 3
Easily tested with automated tests ................................................................................................................................... 3
Traditional and SPA behaviors supported ..................................................................................................................... 3
Simple development and deployment ............................................................................................................................ 4
Traditional ASP.NET and Web Forms ............................................................................................................................... 4
Blazor ............................................................................................................................................................................................ 4
References – Modern Web Applications ................................................................................................................... 4
Choose Between Traditional Web Apps and Single Page Apps (SPAs) ............................. 6
Blazor ............................................................................................................................................................................................ 7
When to choose traditional web apps ............................................................................................................................ 7
When to choose SPAs ............................................................................................................................................................ 8
References – SPA Frameworks ....................................................................................................................................... 8
When to choose Blazor ......................................................................................................................................................... 9
Decision table ............................................................................................................................................................................ 9
Architectural principles......................................................................................................... 10
Common design principles ............................................................................................................................................... 10
Separation of concerns .................................................................................................................................................. 10
Encapsulation ..................................................................................................................................................................... 10
Dependency inversion .................................................................................................................................................... 11
Explicit dependencies ..................................................................................................................................................... 12
Single responsibility ........................................................................................................................................................ 13
Don’t repeat yourself (DRY) ......................................................................................................................................... 13
Persistence ignorance .................................................................................................................................................... 13
i Contents
Bounded contexts ............................................................................................................................................................ 14
Additional resources ............................................................................................................................................................ 14
Common web application architectures ............................................................................. 15
What is a monolithic application? .................................................................................................................................. 15
All-in-one applications ....................................................................................................................................................... 15
What are layers? .................................................................................................................................................................... 16
Traditional “N-Layer” architecture applications ........................................................................................................ 17
Clean architecture ................................................................................................................................................................. 21
Organizing code in Clean Architecture ................................................................................................................... 26
Monolithic applications and containers ....................................................................................................................... 27
Monolithic application deployed as a container ................................................................................................. 29
Docker support ...................................................................................................................................................................... 31
Troubleshooting Docker problems ........................................................................................................................... 32
References – Common web architectures .............................................................................................................. 32
Common client-side web technologies ............................................................................... 33
HTML.......................................................................................................................................................................................... 33
CSS .............................................................................................................................................................................................. 33
CSS preprocessors ........................................................................................................................................................... 34
JavaScript ................................................................................................................................................................................. 35
Legacy web apps with jQuery ..................................................................................................................................... 35
jQuery vs a SPA Framework ......................................................................................................................................... 35
Angular SPAs...................................................................................................................................................................... 36
React ...................................................................................................................................................................................... 37
Vue ......................................................................................................................................................................................... 37
Blazor WebAssembly ...................................................................................................................................................... 38
Choosing a SPA Framework ......................................................................................................................................... 39
References – Client Web Technologies ................................................................................................................... 39
Develop ASP.NET Core MVC apps ....................................................................................... 40
MVC and Razor Pages ......................................................................................................................................................... 40
Why Razor Pages?............................................................................................................................................................ 41
When to use MVC ............................................................................................................................................................ 41
ii Contents
Mapping requests to responses ..................................................................................................................................... 41
Keeping controllers under control ............................................................................................................................ 43
References – Mapping Requests to Responses ................................................................................................... 45
Working with dependencies ............................................................................................................................................. 45
Declare your dependencies .......................................................................................................................................... 46
Structuring the application ............................................................................................................................................... 47
Feature organization ....................................................................................................................................................... 48
APIs and Blazor applications........................................................................................................................................ 49
Cross-cutting concerns .................................................................................................................................................. 50
References – Structuring applications ..................................................................................................................... 52
Security ..................................................................................................................................................................................... 53
Identity ................................................................................................................................................................................. 53
Authentication ................................................................................................................................................................... 55
References – Authentication ........................................................................................................................................ 56
Authorization ..................................................................................................................................................................... 57
References – Security ...................................................................................................................................................... 59
Client communication ......................................................................................................................................................... 59
References – Client Communication ........................................................................................................................ 60
Domain-driven design – Should you apply it? .......................................................................................................... 60
When should you apply DDD ...................................................................................................................................... 61
When shouldn’t you apply DDD ................................................................................................................................ 61
References – Domain-Driven Design ....................................................................................................................... 62
Deployment............................................................................................................................................................................. 62
References – Deployment ............................................................................................................................................. 63
Working with Data in ASP.NET Core Apps ......................................................................... 64
Entity Framework Core (for relational databases) .................................................................................................... 64
The DbContext .................................................................................................................................................................. 64
Configuring EF Core ........................................................................................................................................................ 65
Fetching and storing Data ............................................................................................................................................ 66
Fetching related data ...................................................................................................................................................... 67
Encapsulating data .......................................................................................................................................................... 68
Resilient connections ...................................................................................................................................................... 69
iii Contents
References – Entity Framework Core ........................................................................................................................ 71
EF Core or micro-ORM? ..................................................................................................................................................... 71
SQL or NoSQL ........................................................................................................................................................................ 72
Azure Cosmos DB ................................................................................................................................................................. 73
Other persistence options ................................................................................................................................................. 74
Caching ..................................................................................................................................................................................... 75
ASP.NET Core response caching ................................................................................................................................ 75
Data caching ...................................................................................................................................................................... 76
Getting data to Blazor WebAssembly apps ................................................................................................................ 78
Test ASP.NET Core MVC apps .............................................................................................. 80
Kinds of automated tests ................................................................................................................................................... 80
Unit tests .............................................................................................................................................................................. 80
Integration tests................................................................................................................................................................ 80
Functional tests ................................................................................................................................................................. 81
Testing Pyramid ................................................................................................................................................................ 81
What to test ........................................................................................................................................................................ 82
Organizing test projects ..................................................................................................................................................... 83
Test naming ........................................................................................................................................................................ 84
Unit testing ASP.NET Core apps ..................................................................................................................................... 85
Integration testing ASP.NET Core apps ....................................................................................................................... 87
Functional testing ASP.NET Core apps ......................................................................................................................... 87
References – Test ASP.NET Core MVC apps .......................................................................................................... 90
Development process for Azure .......................................................................................... 91
Vision ......................................................................................................................................................................................... 91
Development environment for ASP.NET Core apps ............................................................................................... 91
Development tools choices: IDE or editor .............................................................................................................. 91
Development workflow for Azure-hosted ASP.NET Core apps .......................................................................... 92
Initial setup ......................................................................................................................................................................... 92
Workflow for developing Azure-hosted ASP.NET Core applications .......................................................... 93
References ............................................................................................................................................................................... 95
Azure hosting recommendations for ASP.NET Core web apps ........................................ 96
iv Contents
Web applications .................................................................................................................................................................. 96
App Service Web Apps .................................................................................................................................................. 96
App Service Web Apps for Containers .................................................................................................................... 98
Azure Kubernetes Service ........................................................................................................................................... 101
Azure Virtual Machines ................................................................................................................................................ 102
Logical processes ................................................................................................................................................................ 102
Data .......................................................................................................................................................................................... 102
Architecture recommendations..................................................................................................................................... 103
v Contents
CHAPTER 1
Characteristics of Modern
Web Applications
“… with proper design, the features come cheaply. This approach is arduous, but continues to
succeed.”
- Dennis Ritchie
Modern web applications have higher user expectations and greater demands than ever before.
Today’s web apps are expected to be available 24/7 from anywhere in the world, and usable from
virtually any device or screen size. Web applications must be secure, flexible, and scalable to meet
spikes in demand. Increasingly, complex scenarios should be handled by rich user experiences built on
the client using JavaScript, and communicating efficiently through web APIs.
ASP.NET Core is optimized for modern web applications and cloud-based hosting scenarios. Its
modular design enables applications to depend on only those features they actually use, improving
application security and performance while reducing hosting resource requirements.
Reference application: eShopOnWeb
This guidance includes a reference application, eShopOnWeb, that demonstrates some of the
principles and recommendations. The application is a simple online store, which supports browsing
through a catalog of shirts, coffee mugs, and other marketing items. The reference application is
deliberately simple in order to make it easy to understand.
1 CHAPTER 1 | Characteristics of Modern Web Applications
Figure 2-1. eShopOnWeb
Reference Application
• eShopOnWeb
https://github.com/dotnet/eShopOnWeb
Cloud-hosted and scalable
ASP.NET Core is optimized for the cloud (public cloud, private cloud, any cloud) because it is low-
memory and high-throughput. The smaller footprint of ASP.NET Core applications means you can
host more of them on the same hardware, and you pay for fewer resources when using pay-as-you-
go cloud hosting services. The higher-throughput means you can serve more customers from an
application given the same hardware, further reducing the need to invest in servers and hosting
infrastructure.
Cross platform
ASP.NET Core is cross-platform and can run on Linux, macOS, and Windows. This capability opens up
many new options for both the development and deployment of apps built with ASP.NET Core.
2 CHAPTER 1 | Characteristics of Modern Web Applications
Docker containers - both Linux and Windows - can host ASP.NET Core applications, allowing them to
take advantage of the benefits of containers and microservices.
Modular and loosely coupled
NuGet packages are first-class citizens in .NET Core, and ASP.NET Core apps are composed of many
libraries through NuGet. This granularity of functionality helps ensure apps only depend on and
deploy functionality they actually require, reducing their footprint and security vulnerability surface
area.
ASP.NET Core also fully supports dependency injection, both internally and at the application level.
Interfaces can have multiple implementations that can be swapped out as needed. Dependency
injection allows apps to loosely couple to those interfaces, rather than specific implementations,
making them easier to extend, maintain, and test.
Easily tested with automated tests
ASP.NET Core applications support unit testing, and their loose coupling and support for dependency
injection makes it easy to swap infrastructure concerns with fake implementations for test purposes.
ASP.NET Core also ships with a TestServer that can be used to host apps in memory. Functional tests
can then make requests to this in-memory server, exercising the full application stack (including
middleware, routing, model binding, filters, etc.) and receiving a response, all in a fraction of the time
it would take to host the app on a real server and make requests through the network layer. These
tests are especially easy to write, and valuable, for APIs, which are increasingly important in modern
web applications.
Traditional and SPA behaviors supported
Traditional web applications have involved little client-side behavior, but instead have relied on the
server for all navigation, queries, and updates the app might need to make. Each new operation made
by the user would be translated into a new web request, with the result being a full page reload in the
end user’s browser. Classic Model-View-Controller (MVC) frameworks typically follow this approach,
with each new request corresponding to a different controller action, which in turn would work with a
model and return a view. Some individual operations on a given page might be enhanced with AJAX
(Asynchronous JavaScript and XML) functionality, but the overall architecture of the app used many
different MVC views and URL endpoints. In addition, ASP.NET Core MVC also supports Razor Pages, a
simpler way to organize MVC-style pages.
Single Page Applications (SPAs), by contrast, involve very few dynamically generated server-side page
loads (if any). Many SPAs are initialized within a static HTML file that loads the necessary JavaScript
libraries to start and run the app. These apps make heavy usage of web APIs for their data needs and
can provide much richer user experiences.
3 CHAPTER 1 | Characteristics of Modern Web Applications
Another Random Scribd Document
with Unrelated Content
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.
Section 3. Information about the Project
Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.
The Foundation’s business office is located at 809 North 1500 West,
Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.
The Foundation is committed to complying with the laws regulating
charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.
While we cannot and do not solicit contributions from states where
we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.
International donations are gratefully accepted, but we cannot make
any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Section 5. General Information About
Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
This website includes information about Project Gutenberg™,
including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com