Skip to content

Commit 77b91b7

Browse files
committed
优化 WebApi
1 parent acbcdd6 commit 77b91b7

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/Senparc.CO2NET.WebApi/Register.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal static void AddApiBind(this IServiceCollection serviceCollection, bool
121121

122122

123123
var coverAllMethods = false;//class 上已经有覆盖所有方法的 [ApiBind] 特性标签
124-
var choosenClass = false;//当前 class 内有需要被引用的对象(且当前 class 可以被实例化)
124+
var hasChildApiAndNonStaticClass = false;//当前 class 内有需要被引用的对象(且当前 class 可以被实例化)
125125

126126
if (typeAttrs.Count() == 0 && CheckAdditionalClass(classType, out string classCategory))
127127
{
@@ -164,9 +164,9 @@ internal static void AddApiBind(this IServiceCollection serviceCollection, bool
164164
}
165165

166166
//判断当前 class 是否包含可用的方法,如果包含,需要标记并进行后期处理
167-
if (!choosenClass)
167+
if (!hasChildApiAndNonStaticClass)
168168
{
169-
choosenClass = coverAllMethods || isApiMethod;//TODO 注意忽略的对象
169+
hasChildApiAndNonStaticClass = coverAllMethods || isApiMethod;//TODO 注意忽略的对象
170170
}
171171

172172
if (isApiMethod)
@@ -186,7 +186,8 @@ internal static void AddApiBind(this IServiceCollection serviceCollection, bool
186186
}
187187
}
188188

189-
if (choosenClass)
189+
var isStaticClass = classType.IsAbstract && classType.IsSealed;
190+
if (hasChildApiAndNonStaticClass && !isStaticClass)
190191
{
191192
//当前类不是静态类,且内部方法被引用,需要进行 DI 配置
192193
serviceCollection.AddScoped(classType);

src/Senparc.CO2NET.WebApi/Senparc.CO2NET.WebApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
4-
<Version>0.2.5.4-preview3</Version>
4+
<Version>0.2.5.6-preview3</Version>
55
<LangVersion>latest</LangVersion>
66
<AssemblyName>Senparc.CO2NET.WebApi</AssemblyName>
77
<RootNamespace>Senparc.CO2NET.WebApi</RootNamespace>

src/Senparc.CO2NET.WebApi/WebApiEngines/WebApiEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private async Task BuildApiMethodForOneThread(IGrouping<string, KeyValuePair<str
396396

397397
//var dt1 = SystemTime.Now;
398398
//修改XML文档
399-
//await BuildXmlDoc(category, methodName, apiMethodInfo, tb);
399+
await BuildXmlDoc(category, methodName, apiMethodInfo, tb);
400400
//WriteLog($"methodName 文档修改耗时:{SystemTime.DiffTotalMS(dt1)}ms");
401401
}
402402
catch (Exception ex)

0 commit comments

Comments
 (0)