@elf-express/admin-net-mcp 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/index.js +83 -88
  2. package/knowledge/Furion_Teaching_Manual/04-1-/351/205/215/347/275/256.md +442 -0
  3. package/knowledge/Furion_Teaching_Manual/04-2-/351/201/270/351/240/205.md +363 -0
  4. package/knowledge/Furion_Teaching_Manual/05-1-/345/213/225/346/205/213WebAPI.md +825 -0
  5. package/knowledge/Furion_Teaching_Manual/05-2-HttpContext.md +217 -0
  6. package/knowledge/Furion_Teaching_Manual/05-3-/347/257/251/351/201/270/345/231/250/346/224/224/346/210/252/345/231/250AOP.md +581 -0
  7. package/knowledge/Furion_Teaching_Manual/05-4-/350/253/213/346/261/202/347/250/275/346/240/270/346/227/245/350/252/214.md +129 -0
  8. package/knowledge/Furion_Teaching_Manual/05-5-/344/270/255/344/273/213/350/273/237/351/253/224Middleware.md +328 -0
  9. package/knowledge/Furion_Teaching_Manual/05-6-Vue-React-Angular/344/273/213/351/235/242/344/273/243/347/220/206.md +317 -0
  10. package/knowledge/Furion_Teaching_Manual/06-1/350/246/217/347/257/204/345/214/226/346/216/245/345/217/243.md +1458 -0
  11. package/knowledge/Furion_Teaching_Manual/06-2/347/254/254/344/270/211/346/226/271API_Scalar.md +91 -0
  12. package/knowledge/Furion_Teaching_Manual/07-/345/217/213/345/245/275/344/276/213/345/244/226/350/231/225/347/220/206.md +511 -0
  13. package/knowledge/Furion_Teaching_Manual/08-1-/350/263/207/346/226/231/351/251/227/350/255/211/345/237/272/347/244/216/344/275/277/347/224/250.md +587 -0
  14. package/knowledge/Furion_Teaching_Manual/10-1-SqlSugar/346/225/264/345/220/210.md +336 -0
  15. package/knowledge/Furion_Teaching_Manual/11-SaaS /345/244/232/347/247/237/346/210/266/347/255/206/350/250/230.md" +271 -0
  16. package/knowledge/Furion_Teaching_Manual/12-furion-dependency-injection.md +408 -0
  17. package/knowledge/Furion_Teaching_Manual/13-/347/211/251/344/273/266/350/263/207/346/226/231/346/230/240/345/260/204/357/274/210Mapster/357/274/211.md +162 -0
  18. package/knowledge/Furion_Teaching_Manual/14-/345/210/206/345/270/203/345/274/217/347/274/223/345/255/230.md +311 -0
  19. package/knowledge/Furion_Teaching_Manual/15-/345/256/211/345/205/250/351/211/264/346/235/203.md +832 -0
  20. package/knowledge/Furion_Teaching_Manual/17-/346/252/242/350/246/226/347/257/204/346/234/254/345/274/225/346/223/216.md +327 -0
  21. package/knowledge/Furion_Teaching_Manual/18-/346/227/245/350/252/214/350/250/230/351/214/204.md +639 -0
  22. package/knowledge/Furion_Teaching_Manual/19-1-HTTP/351/201/240/347/253/257/350/253/213/346/261/202/345/237/272/347/244/216/344/275/277/347/224/250.md +621 -0
  23. package/knowledge/Furion_Teaching_Manual/19-2-HTTP/351/201/240/347/253/257/350/253/213/346/261/202/351/200/262/351/232/216/346/214/207/345/215/227.md +928 -0
  24. package/knowledge/Furion_Teaching_Manual/19-3-HTTP/351/201/240/347/253/257/350/253/213/346/261/202/345/270/270/350/246/213/345/225/217/351/241/214.md +362 -0
  25. package/knowledge/Furion_Teaching_Manual/20-/350/263/207/346/226/231/345/212/240/350/247/243/345/257/206.md +286 -0
  26. package/knowledge/Furion_Teaching_Manual/20-/351/231/204/351/214/204-KSort/350/263/207/346/226/231/347/260/275/345/220/215/345/256/214/346/225/264/345/216/237/345/247/213/347/242/274.md +305 -0
  27. package/knowledge/Furion_Teaching_Manual/21-/345/205/250/347/220/203/345/214/226/345/222/214/346/234/254/345/234/260/345/214/226.md +342 -0
  28. package/knowledge/Furion_Teaching_Manual/22-/344/272/213/344/273/266/345/214/257/346/265/201/346/216/222EventBus.md +448 -0
  29. package/knowledge/Furion_Teaching_Manual/23-JSON/345/272/217/345/210/227/345/214/226.md +340 -0
  30. package/knowledge/Furion_Teaching_Manual/24-/345/215/263/346/231/202/351/200/232/350/250/212SignalR.md +247 -0
  31. package/knowledge/Furion_Teaching_Manual/25-/350/274/224/345/212/251/350/247/222/350/211/262/346/234/215/345/213/231WorkerService.md +295 -0
  32. package/knowledge/Furion_Teaching_Manual/26-1-/346/216/222/347/250/213/344/275/234/346/245/255/345/256/232/346/231/202/344/273/273/345/213/231.md +631 -0
  33. package/knowledge/Furion_Teaching_Manual/26-2-Cron/350/241/250/351/201/224/345/274/217.md +203 -0
  34. package/knowledge/Furion_Teaching_Manual/26-3-/344/273/273/345/213/231/344/275/207/345/210/227TaskQueue.md +215 -0
  35. package/knowledge/Furion_Teaching_Manual/27-/345/210/206/346/225/243/345/274/217ID/347/224/237/346/210/220.md +86 -0
  36. package/knowledge/Furion_Teaching_Manual/28-/346/250/241/347/265/204/345/214/226/351/226/213/347/231/274.md +68 -0
  37. package/knowledge/Furion_Teaching_Manual/29-/346/265/201/350/256/212/347/211/251/344/273/266Clay.md +313 -0
  38. package/knowledge/Furion_Teaching_Manual/30-/350/204/253/346/225/217/350/231/225/347/220/206/357/274/210Sensitive Detection).md" +168 -0
  39. package/knowledge/Furion_Teaching_Manual/32-/346/234/203/350/251/261/345/222/214/347/213/200/346/205/213/347/256/241/347/220/206.md +147 -0
  40. package/knowledge/Furion_Teaching_Manual/33-IPC/347/250/213/345/272/217/351/200/232/350/250/212.md +98 -0
  41. package/knowledge/Furion_Teaching_Manual/34-2-Docker/351/203/250/347/275/262.md +313 -0
  42. package/knowledge/Furion_Teaching_Manual/34-3-Nginx/351/203/250/347/275/262.md +157 -0
  43. package/knowledge/Furion_Teaching_Manual/34-8-WindowsService/351/203/250/347/275/262.md +112 -0
  44. package/knowledge/Furion_Teaching_Manual/35-1-Docker/347/222/260/345/242/203/346/214/201/347/272/214/351/203/250/347/275/262Jenkins.md +169 -0
  45. package/knowledge/Furion_Teaching_Manual/36-1-/345/226/256/345/205/203/346/270/254/350/251/246/346/225/264/345/220/210/346/270/254/350/251/246.md +275 -0
  46. package/knowledge/Furion_Teaching_Manual/36-3-/345/237/272/346/272/226/346/270/254/350/251/246Benchmarking.md +80 -0
  47. package/knowledge/attributes.md +153 -0
  48. package/knowledge/config.md +147 -0
  49. package/knowledge/entity.md +115 -0
  50. package/knowledge/event.md +124 -0
  51. package/knowledge/plugin.md +136 -0
  52. package/knowledge/service.md +146 -0
  53. package/knowledge/sqlsugar.md +172 -0
  54. package/knowledge/vue-typescript.md +338 -0
  55. package/package.json +3 -2
@@ -0,0 +1,363 @@
1
+ # 4.2 选项
2
+
3
+ ## 4.2.1 什么是选项
4
+
5
+ 选项是 ASP.NET Core 推荐的动态读取配置的方式,这种方式将配置文件数据用一个强类型来托管,能够实现配置验证、默认值配置、实时读取等功能。
6
+
7
+ ## 4.2.2 与配置的区别
8
+
9
+ 选项实际上也是配置,但在后者的基础上添加了配置验证、默认值/后期配置设定及提供了多种接口读取配置信息,同时还支持配置更改通知等强大灵活功能。
10
+
11
+ 所以,除了一次性读取使用的配置以外,都应该选用**选项**替换**配置**。
12
+
13
+ ---
14
+
15
+ ## 4.2.3 选项的使用
16
+
17
+ ### 4.2.3.1 配置 appsettings.json 信息
18
+
19
+ ```json
20
+ {
21
+ "AppInfo": {
22
+ "Name": "Furion",
23
+ "Version": "1.0.0",
24
+ "Company": "Baiqian"
25
+ }
26
+ }
27
+ ```
28
+
29
+ ### 4.2.3.2 创建 AppInfoOptions 强类型类
30
+
31
+ ```csharp
32
+ using Furion.ConfigurableOptions;
33
+
34
+ namespace Furion.Application
35
+ {
36
+ public class AppInfoOptions : IConfigurableOptions
37
+ {
38
+ public string Name { get; set; }
39
+ public string Version { get; set; }
40
+ public string Company { get; set; }
41
+ }
42
+ }
43
+ ```
44
+
45
+ > **温馨提示**:建议所有选项类都应该以 `Options` 命名结尾。
46
+ >
47
+ > Furion 框架提供了非常灵活的注册选项服务的方法,只需要继承 `IConfigurableOptions` 接口即可,该接口位于 `Furion.ConfigurableOptions` 命名空间下。
48
+
49
+ ### 4.2.3.3 注册 AppInfoOptions 服务
50
+
51
+ 选项不同于配置,需在应用启动时注册:
52
+
53
+ ```csharp
54
+ // Furion.Web.Core\FurWebCoreStartup.cs
55
+ using Microsoft.AspNetCore.Builder;
56
+ using Microsoft.AspNetCore.Hosting;
57
+ using Microsoft.Extensions.DependencyInjection;
58
+
59
+ namespace Furion.Web.Core
60
+ {
61
+ [AppStartup(800)]
62
+ public sealed class FurWebCoreStartup : AppStartup
63
+ {
64
+ public void ConfigureServices(IServiceCollection services)
65
+ {
66
+ services.AddConfigurableOptions<AppInfoOptions>();
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### 4.2.3.4 读取 AppInfoOptions 信息
73
+
74
+ 在 Furion 框架中,提供了多种读取方式:
75
+
76
+ - 通过 `App.GetConfig<TOptions>(path)` 读取(不推荐)
77
+ - 通过依赖注入以下实例读取:`IOptions<TOptions>`、`IOptionsSnapshot<TOptions>`、`IOptionsMonitor<TOptions>`
78
+ - 通过 `App` 静态类提供的静态方法获取:`App.GetOptions<TOptions>()`、`App.GetOptionsMonitor<TOptions>()`、`App.GetOptionsSnapshot<TOptions>()`
79
+
80
+ > ⚠️ **特别注意**:禁止在主机启动时通过 `App.GetOptions<TOptions>` 获取选项,如需获取配置选项理应通过 `App.GetConfig<TOptions>("配置节点", true)`。
81
+
82
+ **`App.GetConfig<TOptions>(path)` 方式(不推荐,仅 ConfigureServices 启动时使用):**
83
+
84
+ ```csharp
85
+ using Furion.Application;
86
+ using Microsoft.AspNetCore.Mvc;
87
+
88
+ namespace Furion.Web.Entry.Controllers
89
+ {
90
+ [Route("api/[controller]")]
91
+ public class DefaultController : ControllerBase
92
+ {
93
+ [HttpGet]
94
+ public string Get()
95
+ {
96
+ var appInfo = App.GetConfig<AppInfoOptions>("AppInfo", true);
97
+ return $@"名称:{appInfo.Name},
98
+ 版本:{appInfo.Version},
99
+ 公司:{appInfo.Company}";
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### 4.2.3.5 如何选择读取方式
106
+
107
+ - 如果选项需要在多个地方使用,则无论任何时候都**不推荐**使用 `App.GetOptions<TOptions>()`
108
+ - 在可依赖注入类中,依赖注入 `IOptions[Snapshot|Monitor]<TOptions>` 读取
109
+ - 在静态类/非依赖注入类中,选择 `App.GetOptions[Snapshot|Monitor]<TOptions>()` 读取
110
+
111
+ ---
112
+
113
+ ## 4.2.4 选项接口说明
114
+
115
+ ASP.NET Core 应用提供了多种读取选项的接口:
116
+
117
+ **`IOptions<TOptions>`**
118
+
119
+ - 不支持在应用启动后读取配置数据
120
+ - 不支持命名选项
121
+ - 注册为单一实例且可以注入到任何服务生存期
122
+
123
+ **`IOptionsSnapshot<TOptions>`**
124
+
125
+ - 在每次请求时应重新计算选项的方案中有用
126
+ - 注册为范围内,因此无法注入到单一实例服务
127
+ - 支持命名选项
128
+
129
+ **`IOptionsMonitor<TOptions>`**
130
+
131
+ - 用于检索选项并管理 `TOptions` 实例的选项通知
132
+ - 注册为单一实例且可以注入到任何服务生存期
133
+ - 支持更改通知、命名选项、可重载配置、选择性选项失效(`IOptionsMonitorCache<TOptions>`)
134
+
135
+ > **注意事项**:在使用 `IConfigurableOptionsListener` 监听选项后,如要获取最新的配置信息,请使用 `App.GetOptionsMonitor<TOptions>()` 而不是 `App.GetOptions<TOptions>()`。
136
+
137
+ ---
138
+
139
+ ## 4.2.5 选项自定义配置
140
+
141
+ 选项实际上需要和配置文件特定键值挂钩,Furion 通过以下流程自动查找键值。
142
+
143
+ ### 4.2.5.1 选项查找键流程
144
+
145
+ **没有贴 `[OptionsSettings]` 特性时:**
146
+
147
+ - 以 `Options` 结尾,则去除 `Options` 字符串作为键名
148
+ - 否则返回类名称
149
+
150
+ ```csharp
151
+ // 以 Options 结尾,键名为:AppInfo
152
+ public class AppInfoOptions : IConfigurableOptions
153
+ {
154
+ public string Name { get; set; }
155
+ public string Version { get; set; }
156
+ public string Company { get; set; }
157
+ }
158
+
159
+ // 不以 Options 结尾,键名为:AppInfoSettings
160
+ public class AppInfoSettings : IConfigurableOptions
161
+ {
162
+ public string Name { get; set; }
163
+ public string Version { get; set; }
164
+ public string Company { get; set; }
165
+ }
166
+ ```
167
+
168
+ **贴了 `[OptionsSettings]` 特性时:**
169
+
170
+ - 如果配置了 `Path` 属性,则返回 `Path` 的值
171
+ - 否则返回类名称
172
+
173
+ ---
174
+
175
+ ## 4.2.6 [OptionsSettings] 说明
176
+
177
+ 选项类可以通过 `[OptionsSettings]` 来配置查找路径值:
178
+
179
+ | 属性 | 说明 |
180
+ |------|------|
181
+ | `Path` | 对应配置文件中的键,支持分层键字符串 |
182
+ | `PostConfigureAll` | 选项后期配置,默认 `false` |
183
+
184
+ ---
185
+
186
+ ## 4.2.7 选项验证
187
+
188
+ 选项支持验证配置有效性,通过 `services.AddConfigurableOptions<TOptions>()` 注册选项默认启用了验证支持。
189
+
190
+ **特性方式(DataAnnotations):**
191
+
192
+ ```csharp
193
+ using Furion.ConfigurableOptions;
194
+ using System.ComponentModel.DataAnnotations;
195
+
196
+ namespace Furion.Application
197
+ {
198
+ public class AppInfoOptions : IConfigurableOptions
199
+ {
200
+ [Required(ErrorMessage = "名称不能为空")]
201
+ public string Name { get; set; }
202
+
203
+ [Required, RegularExpression(@"^[0-9][0-9\.]+[0-9]$", ErrorMessage = "不是有效的版本号")]
204
+ public string Version { get; set; }
205
+
206
+ [Required, MaxLength(100)]
207
+ public string Company { get; set; }
208
+ }
209
+ }
210
+ ```
211
+
212
+ **自定义复杂验证:** 实现 `IValidateOptions<TOptions>` 接口。
213
+
214
+ > **特别说明**:`IConfigurableOptions<TOptions, TOptionsValidation>` 继承自 `IConfigurableOptions<TOptions>`,也就是自定义复杂验证默认具有 `PostConfigure(TOptions options)` 选项后期配置方法。
215
+
216
+ ---
217
+
218
+ ## 4.2.8 选项后期配置
219
+
220
+ 选项后期配置可以在运行时解析值或设定默认值/后期配置等。只需要继承 `IConfigurableOptions<TOptions>` 接口并实现 `PostConfigure` 方法:
221
+
222
+ ```csharp
223
+ using Furion.ConfigurableOptions;
224
+ using Microsoft.Extensions.Configuration;
225
+ using System.ComponentModel.DataAnnotations;
226
+
227
+ namespace Furion.Application
228
+ {
229
+ public class AppInfoOptions : IConfigurableOptions<AppInfoOptions>
230
+ {
231
+ [Required(ErrorMessage = "名称不能为空")]
232
+ public string Name { get; set; }
233
+
234
+ [Required]
235
+ public string Version { get; set; }
236
+
237
+ [Required, MaxLength(100)]
238
+ public string Company { get; set; }
239
+
240
+ public void PostConfigure(AppInfoOptions options, IConfiguration configuration)
241
+ {
242
+ options.Name ??= "Furion";
243
+ options.Version ??= "1.0.0";
244
+ options.Company ??= "Baiqian";
245
+ }
246
+ }
247
+ }
248
+ ```
249
+
250
+ ---
251
+
252
+ ## 4.2.9 选项更改通知(热更新)
253
+
254
+ 只需要继承 `IConfigurableOptionsListener<TOptions>` 接口并实现 `OnListener` 方法即可。`appsettings.json` 或自定义配置文件发生任何更改都会触发处理方法。
255
+
256
+ ```csharp
257
+ using Furion.ConfigurableOptions;
258
+
259
+ namespace Furion.Application
260
+ {
261
+ public class AppInfoOptions : IConfigurableOptionsListener<AppInfoOptions>
262
+ {
263
+ public string Name { get; set; }
264
+ public string Version { get; set; }
265
+ public string Company { get; set; }
266
+
267
+ public void OnListener(AppInfoOptions options, IConfiguration configuration)
268
+ {
269
+ var name = options.Name; // 实时的最新值
270
+ var version = options.Version; // 实时的最新值
271
+ }
272
+
273
+ public void PostConfigure(AppInfoOptions options, IConfiguration configuration)
274
+ {
275
+ }
276
+ }
277
+ }
278
+ ```
279
+
280
+ > **特别说明**:`IConfigurableOptionsListener<TOptions>` 继承自 `IConfigurableOptions<TOptions>`。
281
+
282
+ ### 4.2.9.1 关于多次触发问题
283
+
284
+ `ChangeToken.OnChange` 监听文件更改会导致 `OnListener` 触发两次,这是 .NET Core 本身存在的问题。
285
+
286
+ Furion 框架提供了替代方案,通过局部注入 `IOptionsMonitor` 的方式:
287
+
288
+ ```csharp
289
+ public class YourService : IYourService, IDisposable
290
+ {
291
+ private readonly IDisposable _optionsReloadToken;
292
+ private YourOptions _options;
293
+
294
+ public YourService(IOptionsMonitor<YourOptions> options)
295
+ {
296
+ (_optionsReloadToken, _options) = (options.OnChange(ReloadOptions), options.CurrentValue);
297
+
298
+ // Furion 4.9.5.13+ 版本支持,解决重复触发问题
299
+ // (_optionsReloadToken, _options) = (options.OnChange(((Action<YourOptions>)ReloadOptions).Debounce()), options.CurrentValue);
300
+ }
301
+
302
+ private void ReloadOptions(YourOptions options)
303
+ {
304
+ _options = options;
305
+ }
306
+
307
+ public void Dispose()
308
+ {
309
+ _optionsReloadToken?.Dispose();
310
+ }
311
+ }
312
+ ```
313
+
314
+ ---
315
+
316
+ ## 4.2.10 选项的优缺点
317
+
318
+ **优点:**
319
+
320
+ - 强类型配置
321
+ - 提供多种读取方式
322
+ - 支持热加载
323
+ - 支持设置默认值/后期配置
324
+ - 支持在运行环境中动态配置
325
+ - 支持验证配置有效性
326
+ - 支持更改通知
327
+ - 支持命名选项
328
+
329
+ **缺点:**
330
+
331
+ - 需要定义对应类型
332
+ - 需要在启动时注册
333
+
334
+ ---
335
+
336
+ ## 4.2.11 自定义属性 Key 映射
337
+
338
+ > **版本说明**:仅限 Furion v3.4.3+ 版本使用。
339
+
340
+ 有时候 `appsettings.json` 中配置的 Key 和选项定义的属性名不一样,使用 `[MapSettings]` 特性即可:
341
+
342
+ ```json
343
+ {
344
+ "AppInfo": {
345
+ "Name": "Furion",
346
+ "Version": "1.0.0",
347
+ "Company_Name": "Baiqian"
348
+ }
349
+ }
350
+ ```
351
+
352
+ ```csharp
353
+ public class AppInfoOptions : IConfigurableOptions
354
+ {
355
+ public string Name { get; set; }
356
+ public string Version { get; set; }
357
+
358
+ [MapSettings("Company_Name")]
359
+ public string Company { get; set; }
360
+ }
361
+ ```
362
+
363
+ > **特别注意**:`[MapSettings]` 配置的 Key 会自动应用选项的 Key 作为起始点,如实际上 `Company` 属性对应的 Key 为 `AppInfo:Company_Name`。