使用 ASP.NET Core 和 Azure 架構現代化 Web 應用程式Architect Modern Web Applications with ASP.NET Core and Azure

《建築師現代 Web 應用程式指南》的封面圖像。

編輯 v3.1 - 更新至ASP.NET核心 3.1EDITION v3.1 - Updated to ASP.NET Core 3.1

發行者PUBLISHED BY

Microsoft 開發人員部門 .NET 和 Visual Studio 產品小組Microsoft Developer Division, .NET, and Visual Studio product teams

Microsoft Corporation 部門A division of Microsoft Corporation

One Microsoft WayOne Microsoft Way

Redmond, Washington 98052-6399Redmond, Washington 98052-6399

版權© 2020 年由微軟公司Copyright © 2020 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. 本書中所述之觀點、意見與資訊 (包括 URL 及其他網際網路網站參考) 可能會隨時變更,恕不另行通知。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 與列於 https://www.microsoft.com「商標」網頁的商標是 Microsoft 集團的商標。Microsoft and the trademarks listed at https://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies.

Mac 與 macOS 是 Apple Inc. 的商標。Mac and macOS are trademarks of Apple Inc.

Docker 鯨魚標誌是 Docker, 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 - 軟體架構設計人員和講師 - Ardalis.comSteve "ardalis" Smith - Software Architect and Trainer - Ardalis.com

編輯者:Editors:

Maira WenzelMaira Wenzel

簡介Introduction

.NET Core 和 ASP.NET Core 提供許多優於傳統.NET 開發的優點。.NET Core and ASP.NET Core offer several advantages over traditional .NET development. 如果下列部分或所有項目對應用程式成功而言十分重要,則您應該將 .NET Core 用於伺服器應用程式:You should use .NET Core for your server applications if some or all of the following are important to your application's success:

  • 跨平台支援。Cross-platform support.

  • 使用微服務。Use of microservices.

  • 使用 Docker 容器。Use of Docker containers.

  • 高效能和延展性需求。High performance and scalability requirements.

  • 相同伺服器上應用程式之 .NET 版本的並存版本控制。Side-by-side versioning of .NET versions by application on the same server.

傳統 .NET 應用程式可以並確實支援這些需求,但 ASP.NET Core 和 .NET Core 已最佳化可提供針對上述案例的改善支援。Traditional .NET applications can and do support many of these requirements, but ASP.NET Core and .NET Core have been optimized to offer improved support for the above scenarios.

越來越多的組織會選擇使用 Microsoft Azure 這類服務,以在雲端中裝載其 Web 應用程式。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.

使用 ASP.NET Core 建置 Web 應用程式 (且其裝載於 Azure) 提供許多比傳統替代項目更具競爭性的優點。Building web applications with ASP.NET Core, hosted in Azure, offers many competitive advantages over traditional alternatives. ASP.NET Core 已針對現代化 Web 應用程式開發做法和雲端裝載案例最佳化。ASP.NET Core is optimized for modern web application development practices and cloud hosting scenarios. 在本指南中,您將學習如何架構 ASP.NET Core 應用程式,以善加利用這些功能。In this guide, you'll learn how to architect your ASP.NET Core applications to best take advantage of these capabilities.

目的Purpose

本指南提供有關使用 ASP.NET核心和 Azure 構建單片Web 應用程式提供的端到端指南。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.

本指南是對".NET 微服務"的補充。容器化 .NET 應用程式的體系結構",它更側重于 Docker、微服務和容器部署以承載企業應用程式。This guide is complementary to the ".NET Microservices. Architecture for Containerized .NET Applications" which focuses more on Docker, Microservices, and Deployment of Containers to host enterprise applications.

.NET 微服務。.NET Microservices. 容器化 .NET 應用程式的架構Architecture for Containerized .NET Applications

誰應該使用本指南Who should use this guide

本指南的對象主要是開發人員、開發負責人和架構設計人員,而他們對使用 Microsoft 技術和服務在雲端中建置現代化 Web 應用程式感興趣。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.

次要對象是技術決策者,其已熟悉 ASP.NET 或 Azure,並尋找是否可以升級為新專案或現有專案之 ASP.NET Core 的相關資訊。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

本指南已壓縮成相當小的文件,著重於使用現代化 .NET 技術和 Windows Azure 來建置 Web 應用程式。This guide has been condensed into a relatively small document that focuses on building web applications with modern .NET technologies and Windows 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