Blame view

netcore/src/Infrastructure/NCC/DynamicApiController/Options/DynamicApiControllerSettingsOptions.cs 3.49 KB
de2bd2f9   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  using NCC.ConfigurableOptions;
  using Microsoft.Extensions.Configuration;
  using System.ComponentModel.DataAnnotations;
  
  namespace NCC.DynamicApiController
  {
      /// <summary>
      /// 动态接口控制器配置
      /// </summary>
      public sealed class DynamicApiControllerSettingsOptions : IConfigurableOptions<DynamicApiControllerSettingsOptions>
      {
          /// <summary>
          /// 默认路由前缀
          /// </summary>
          public string DefaultRoutePrefix { get; set; }
  
          /// <summary>
          /// 默认请求谓词
          /// </summary>
          [Required]
          public string DefaultHttpMethod { get; set; }
  
          /// <summary>
          /// 默认模块名称
          /// </summary>
          public string DefaultModule { get; set; }
  
          /// <summary>
          /// 小写路由
          /// </summary>
          public bool? LowercaseRoute { get; set; }
  
          /// <summary>
          /// 保留行为名称谓词
          /// </summary>
          public bool? KeepVerb { get; set; }
  
          /// <summary>
          /// 保留名称
          /// </summary>
          public bool? KeepName { get; set; }
  
          /// <summary>
          /// 骆驼命名分隔符
          /// </summary>
          public string CamelCaseSeparator { get; set; }
  
          /// <summary>
          /// 版本号分隔符
          /// </summary>
          [Required]
          public string VersionSeparator { get; set; }
  
          /// <summary>
          /// 模型转查询参数(只有GETHEAD请求有效)
          /// </summary>
          public bool? ModelToQuery { get; set; }
  
          /// <summary>
          /// 支持Mvc控制器处理
          /// </summary>
          public bool? SupportedMvcController { get; set; }
  
          /// <summary>
          /// 配置参数 [FromQuery] 化,默认 false ([FromRoute])
          /// </summary>
          public bool? UrlParameterization { get; set; }
  
          /// <summary>
          /// 被舍弃的控制器名称前后缀
          /// </summary>
          public string[] AbandonControllerAffixes { get; set; }
  
          /// <summary>
          /// 被舍弃的行为名称前后缀
          /// </summary>
          public string[] AbandonActionAffixes { get; set; }
  
          /// <summary>
          /// 复写默认配置路由规则配置
          /// </summary>
          public object[][] VerbToHttpMethods { get; set; }
  
          /// <summary>
          /// 默认区域
          /// </summary>
          public string DefaultArea { get; set; }
  
          /// <summary>
          /// 选项后期配置
          /// </summary>
          /// <param name="options"></param>
          /// <param name="configuration"></param>
          public void PostConfigure(DynamicApiControllerSettingsOptions options, IConfiguration configuration)
          {
              options.DefaultRoutePrefix ??= "api";
              options.DefaultHttpMethod ??= "POST";
              options.LowercaseRoute ??= true;
              options.KeepVerb ??= false;
              options.KeepName ??= false;
              options.CamelCaseSeparator ??= "-";
              options.VersionSeparator ??= "@";
              options.ModelToQuery ??= false;
              options.SupportedMvcController ??= false;
              options.AbandonControllerAffixes ??= new string[]
              {
                  "AppServices",
                  "AppService",
                  "ApiController",
                  "Controller",
                  "Services",
                  "Service"
              };
              options.AbandonActionAffixes ??= new string[]
              {
                  "Async"
              };
          }
      }
  }