Skip to content

Commit a085866

Browse files
committed
refactor(HttpInvoke): 重命名方法并添加默认应用上下文切换
将 ChangeCurrentContextMethod 重命名为 UseAppMethod 以更准确反映其功能 添加 UseDefaultApp 方法以支持切换到默认应用上下文
1 parent 7c62fc9 commit a085866

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

Core/Mud.ServiceCodeGenerator/HttpInvoke/Generators/ConstructorGenerator.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private void GenerateHelperMethods()
163163
if (_context.HasInheritedFrom) return;
164164

165165
GenerateGetMediaTypeMethod();
166-
GenerateChangeCurrentContextMethod();
166+
GenerateUseAppMethod();
167167
}
168168

169169
/// <summary>
@@ -221,22 +221,35 @@ private void GenerateGetTokeTypeMethod()
221221
_codeBuilder.AppendLine();
222222
}
223223

224-
private void GenerateChangeCurrentContextMethod()
224+
private void GenerateUseAppMethod()
225225
{
226226
if (!_context.HasTokenManager)
227227
return;
228228

229229
_codeBuilder.AppendLine(" /// <summary>");
230-
_codeBuilder.AppendLine(" /// 获取用于远程API访问的<see cref = \"TokenType\"/>令牌类型。");
230+
_codeBuilder.AppendLine(" /// 切换到指定的飞书应用上下文。");
231231
_codeBuilder.AppendLine(" /// </summary>");
232-
_codeBuilder.AppendLine(" /// <returns>返回<see cref = \"TokenType\"/>令牌类型。</returns>");
233-
_codeBuilder.AppendLine($" public IMudAppContext ChangeCurrentContext(string appKey)");
232+
_codeBuilder.AppendLine(" /// <returns>返回切换后的应用上下文。</returns>");
233+
_codeBuilder.AppendLine($" public IMudAppContext UseApp(string appKey)");
234234
_codeBuilder.AppendLine(" {");
235235
_codeBuilder.AppendLine(" _appContext = _appManager.GetApp(appKey);");
236236
_codeBuilder.AppendLine(" if(_appContext == null)");
237237
_codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到指定的应用上下文,AppKey: {appKey}\");");
238238
_codeBuilder.AppendLine(" return _appContext;");
239239
_codeBuilder.AppendLine(" }");
240240
_codeBuilder.AppendLine();
241+
242+
_codeBuilder.AppendLine(" /// <summary>");
243+
_codeBuilder.AppendLine(" /// 切换到默认的飞书应用上下文。");
244+
_codeBuilder.AppendLine(" /// </summary>");
245+
_codeBuilder.AppendLine(" /// <returns>返回默认的应用上下文。</returns>");
246+
_codeBuilder.AppendLine($" public IMudAppContext UseDefaultApp()");
247+
_codeBuilder.AppendLine(" {");
248+
_codeBuilder.AppendLine(" _appContext = _appManager.GetDefaultApp();");
249+
_codeBuilder.AppendLine(" if(_appContext == null)");
250+
_codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到默认的应用上下文。\");");
251+
_codeBuilder.AppendLine(" return _appContext;");
252+
_codeBuilder.AppendLine(" }");
253+
_codeBuilder.AppendLine();
241254
}
242255
}

0 commit comments

Comments
 (0)