Ultimate ASP.NET Core Web API Table Of Contents

Ultimate ASP.NET Core Web API

TABLE OF CONTENTS …… 3
目录

1 PROJECT CONFIGURATION …… 11
项目配置

1.1 Creating a New Project…… 11
创建新项目

1.2 launchSettings.json File Configuration …… 13
launchSettings.json 文件配置

1.3 Program.cs and Startup.cs Explanations …… 14
Program.cs and Startup.cs 文件解析

1.4 Extension Methods and CORS Configuration …… 16
扩展方法和 CORS 配置

1.5 IIS Configuration …… 17
IIS 配置

1.6 Additional Code in the Startup Class …… 19
启动类(Startup)中的其他代码

1.7 Environment-Based Settings …… 20
环境设置

2 CONFIGURING A LOGGING SERVICE …… 23
配置日志记录服务

2.1 Creating the Required Projects …… 23
创建所需项目

2.2 Creating the ILoggerManager Interface and Installing NLog …… 24
创建 ILoggerManager 接口并安装 NLog

2.3 Implementing the Interface and Nlog.Config File …… 26
实现接口和 Nlog.Config 文件

2.4 Configuring Logger Service for Logging Messages …… 27
配置记录器服务以记录消息

2.5 DI, IoC, and Logger Service Testing …… 29
DI、IoC 和记录器服务测试

3 DATABASE MODEL AND REPOSITORY PATTERN …… 31
数据库模型和存储库模式

3.1 Creating Models …… 31
创建模型

3.2 Context Class and the Database Connection …… 33
上下文类和数据库连接

3.3 Migration and Initial Data Seed …… 35
迁移和初始数据种子

3.4 Repository Pattern Logic …… 38
存储库模式逻辑

3.5 Repository User Interfaces and Classes …… 40
存储库用户界面和类

3.6 Creating a Repository Manager …… 42
创建存储库管理器

4 HANDLING GET REQUESTS …… 46
处理获取请求

4.1 Controllers and Routing in WEB API …… 46
WEB API中的控制器和路由

4.2 Naming Our Resources …… 48
命名我们的资源

4.3 Getting All Companies From the Database …… 49
从数据库中获取所有公司数据

4.4 Testing the Result with Postman …… 52
使用Postman测试结果

4.5 DTO Classes vs. Entity Model Classes …… 54
DTO 类与实体模型类

4.6 Using AutoMapper in ASP.NET Core …… 57
在 ASP.NET Core中使用自动映射器

5 GLOBAL ERROR HANDLING …… 60
全局错误处理

5.1 Handling Errors Globally with the Built-In Middleware…… 60
使用内置中间件全局处理错误

5.2 Startup Class Modification …… 61
启动(Startup)类修改

5.3 Testing the Result …… 62
测试结果

6 GETTING ADDITIONAL RESOURCES …… 64
获取其他资源

6.1 Getting a Single Resource From the Database …… 64
从数据库中获取单个资源

6.2 Parent/Child Relationships in Web API …… 66
Web API 中的父子关系

6.3 Getting a Single Employee for Company …… 69
为公司招聘一名员工

7 CONTENT NEGOTIATION …… 72
内容协商

7.1 What Do We Get Out of the Box? …… 72
我们从盒子里得到什么?

7.2 Changing the Default Configuration of Our Project …… 73
更改项目的默认配置

7.3 Testing Content Negotiation …… 74
测试内容协商

7.4 Restricting Media Types …… 74
限制媒体类型

7.5 More About Formatters …… 75
更多格式

7.6 Implementing a Custom Formatter …… 76
实现自定义格式

8 METHOD SAFETY AND METHOD IDEMPOTENCY …… 79
方法安全性和方法幂等性

9 CREATING RESOURCES …… 81
创建资源

9.1 Handling POST Requests …… 81
处理POST请求

9.2 Code Explanation …… 83
代码说明

9.3 Creating a Child Resource …… 85
创建子资源

9.4 Creating Children Resources Together with a Parent …… 88
与父资源一起创建子资源

9.5 Creating a Collection of Resources …… 90
创建资源集合

9.6 Model Binding in API …… 93
API中的模型绑定

10 WORKING WITH DELETE REQUESTS …… 97
使用DELETE请求

10.1 Deleting a Parent Resource with its Children …… 98
删除父资源及其子资源

11 WORKING WITH PUT REQUESTS …… 101
使用 PUT 请求

11.1 Updating Employee …… 101
更新员工

11.1.1 About the Update Method from the RepositoryBase Class ……104
关于存储库库类中的更新方法

11.2 Inserting Resources while Updating One …… 105
在更新时插入资源

12 WORKING WITH PATCH REQUESTS …… 107
处理PATCH请求

12.1 Applying PATCH to the Employee Entity …… 108
将 PATCH 应用于员工实体

13 VALIDATION …… 114
验证

13.1 Validation while Creating Resource …… 115
创建资源时的验证

13.1.1 Validating Int Type ……119
验证Int类型

13.2 Validation for PUT Requests …… 121
PUT请求的验证

13.3 Validation for PATCH Requests …… 123
补丁请求的验证

14 ASYNCHRONOUS CODE …… 127
异步代码

14.1 What is Asynchronous Programming? …… 127
什么是异步编程

14.2 Async, Await Keywords, and Return Types …… 128
Async, Await关键字和返回类型

14.2.1 The IRepositoryBase Interface and the RepositoryBase Class Explanation …… 130
IRepositoryBase接口和RepositoryBase类说明

14.3 Modifying the ICompanyRepository Interface and the CompanyRepository Class …… 130
修改ICompanyRepository接口和CompanyRepositoryClass

14.4 IRepositoryManager and RepositoryManager Changes…… 131
IRepositoryManager 和 RepositoryManager变更

14.5 Controller Modification …… 132
控制器修改

15 ACTION FILTERS …… 136
动作过滤器

15.1 Action Filters Implementation …… 136
行动过滤器的实施

15.2 The Scope of Action Filters …… 137
行动范围

15.3 Order of Invocation …… 138
调用顺序

15.4 Improving the Code with Action Filters …… 140
使用动作过滤器改进代码

15.5 Validation with Action Filters …… 140
使用动作过滤器进行验证

15.6 Dependency Injection in Action Filters …… 144
依赖注入在用过滤器

16 PAGING …… 150
分页

16.1 What is Paging? …… 150
什么是分页

16.2 Paging Implementation …… 151
分页实现

16.3 Concrete Query …… 153
具体查询

16.4 Improving the Solution …… 156
改进解决方案

16.4.1 Additional Advice ……159
其他建议

17 FILTERING …… 160
筛选(过滤)

17.1 What is Filtering? …… 160
什么是筛选

17.2 How is Filtering Different from Searching? …… 161
筛选与搜索有何不同

17.3 How to Implement Filtering in ASP.NET Core Web API …… 162
如何在 ASP.NET 核心 Web API 中实现筛选

17.4 Sending and Testing a Query …… 164
发送和测试查询

18 SEARCHING …… 167
搜索

18.1 What is Searching?…… 167
什么是搜索

18.2 Implementing Searching in Our Application …… 167
在我们的应用程序中实现搜索

18.3 Testing Our Implementation …… 169
测试我们的实现

19 SORTING …… 172
排序

19.1 What is Sorting? …… 172
什么是排序

19.2 How to Implement Sorting in ASP.NET Core Web API …… 174
如何在 ASP.NET 核心 Web API中实现排序

19.3 Implementation – Step by Step …… 176
实施 – 逐步执行

19.4 Testing Our Implementation …… 178
测试我们的实现

19.5 Improving the Sorting Functionality…… 179
改进排序功能

20 DATA SHAPING …… 182
数据整形

20.1 What is Data Shaping? …… 182
什么是数据整形

20.2 How to Implement Data Shaping …… 183
如何实现数据整形

20.3 Step-by-Step Implementation …… 185
分步实施

20.4 Resolving XML Serialization Problems …… 189
解决 XML 序列化问题

21 SUPPORTING HATEOAS …… 192
支持HATEOAS

21.1 What is HATEOAS and Why is it so Important?…… 192
什么是HATEOAS,为什么它如此重要?

21.1.1 Typical Response with HATEOAS Implemented ……193
对 HATEOAS 实施的典型响应

21.1.2 What is a Link? ……193
什么是链接

21.1.3 Pros/Cons of Implementing HATEOAS ……194
实施 HATEOAS 的利弊

21.2 Adding Links in the Project …… 194
在项目中添加链接

21.3 Additional Project Changes …… 197
其他项目变更

21.4 Adding Custom Media Types …… 198
添加自定义媒体类型

21.4.1 Registering Custom Media Types ……199
注册自定义媒体类型

21.4.2 Implementing a Media Type Validation Filter ……200
实现媒体类型验证筛选器

21.5 Implementing HATEOAS …… 201
实施 HATEOAS

22 WORKING WITH OPTIONS AND HEAD REQUESTS …… 207
使用选项和 HEAD 请求

22.1 OPTIONS HTTP Request …… 207
选项 HTTP 请求

22.2 OPTIONS Implementation …… 207
执行情况

22.3 Head HTTP Request …… 209
头 HTTP 请求

22.4 HEAD Implementation …… 209
执行

23 ROOT DOCUMENT …… 211
根文档

23.1 Root Document Implementation …… 211
根文档实现

24 VERSIONING APIS …… 216
版本控制

24.1 Required Package Installation and Configuration…… 216
所需的软件包安装和配置

24.2 Versioning Examples …… 218
版本控制示例

24.2.1 Using Query String ……219
使用查询字符串

24.2.2 Using URL Versioning ……220
使用 URL 版本控制

24.2.3 HTTP Header Versioning ……221
HTTP 标头版本控制

24.2.4 Deprecating Versions ……222
弃用版本

24.2.5 Using Conventions ……223
使用约定

25 CACHING …… 224
缓存

25.1 About Caching …… 224
关于缓存

25.1.1 Cache Types ……224
缓存类型

25.1.2 Response Cache Attribute ……225
响应缓存属性

25.2 Adding Cache Headers…… 225
添加缓存标头

25.3 Adding Cache-Store …… 227
添加缓存存储

25.4 Expiration Model …… 229
过期型号

25.5 Validation Model…… 231
验证模型

25.6 Supporting Validation…… 233
支持验证

25.6.1 Configuration ……234
配置

25.7 Using ETag and Validation …… 236
使用 ETag 和验证

26 RATE LIMITING AND THROTTLING …… 240
速率限制和节流

26.1 Implementing Rate Limiting …… 240
实施速率限制

27 JWT AND IDENTITY …… 244
JWT和身份验证

27.1 Implementing Identity in ASP.NET Core Project…… 244
在项目中实现 ASP.NET Core身份验证

27.2 Creating Tables and Inserting Roles …… 246
创建表和插入角色

27.3 User Creation …… 248
用户创建

27.4 Big Picture …… 251
全局

27.5 About JWT …… 252
关于JWT

27.6 JWT Configuration …… 254
JWT配置

27.7 Protecting Endpoints …… 256
保护Endpoints

27.8 Implementing Authentication …… 257
实现身份验证

27.9 Role-Based Authorization …… 263
基于角色的授权

28 DOCUMENTING API WITH SWAGGER …… 266
使用 SWAGGER 文档API

28.1 About Swagger …… 266
关于Swagger

28.2 Swagger Integration Into Our Project …… 267
将Swagger整合进项目

28.3 Adding Authorization Support …… 271
添加授权支持

28.4 Extending Swagger Configuration …… 274
扩展 Swagger 配置

29 DEPLOYMENT TO IIS …… 278
部署到 IIS

29.1 Creating Publish Files …… 278
创建发布文件

29.2 Windows Server Hosting Bundle …… 280
Windows Server Hosting Bundle

29.3 Installing IIS…… 280
安装 IIS

29.4 Configuring Environment File …… 283
配置环境文件

29.5 Testing Deployed Application …… 285
测试已部署的应用程序