1- using Microsoft . AspNetCore . Mvc ;
2- using Microsoft . Extensions . DependencyInjection ;
1+ using Microsoft . Extensions . DependencyInjection ;
32using Senparc . CO2NET . ApiBind ;
43using Senparc . CO2NET . Trace ;
54using System ;
87using System . Linq ;
98using System . Reflection ;
109using System . Reflection . Emit ;
11- using System . Text ;
1210using System . Threading . Tasks ;
1311
1412namespace Senparc . CO2NET . WebApi . WebApiEngines
@@ -31,10 +29,11 @@ public static class WebApiEngineExtensions
3129 /// <param name="additionalAttributes"></param>
3230 /// <param name="buildXml">是否创建动态 API 对应的 XML 注释文件</param>
3331 /// <param name="additionalAttributeFunc">是否复制自定义特性(AppBindAttribute 除外)</param>
32+ /// <param name="forbiddenExternalAccess">是否允许外部访问,默认为 false,只允许本机访问相关 API</param>
3433 public static void AddAndInitDynamicApi ( this IServiceCollection services , IMvcCoreBuilder builder ,
35- string docXmlPath , ApiRequestMethod defaultRequestMethod = ApiRequestMethod . Post , Type baseApiControllerType = null , int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null )
34+ string docXmlPath , ApiRequestMethod defaultRequestMethod = ApiRequestMethod . Post , Type baseApiControllerType = null , int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null , bool forbiddenExternalAccess = true )
3635 {
37- AddAndInitDynamicApi ( services , ( builder , null ) , docXmlPath , defaultRequestMethod , baseApiControllerType , taskCount , showDetailApiLog , copyCustomAttributes , additionalAttributeFunc ) ;
36+ AddAndInitDynamicApi ( services , ( builder , null ) , docXmlPath , defaultRequestMethod , baseApiControllerType , taskCount , showDetailApiLog , copyCustomAttributes , additionalAttributeFunc , forbiddenExternalAccess ) ;
3837 }
3938
4039
@@ -50,10 +49,11 @@ public static void AddAndInitDynamicApi(this IServiceCollection services, IMvcCo
5049 /// <param name="taskCount"></param>
5150 /// <param name="additionalAttributes"></param>
5251 /// <param name="additionalAttributeFunc">是否复制自定义特性(AppBindAttribute 除外)</param>
52+ /// <param name="forbiddenExternalAccess">是否允许外部访问,默认为 false,只允许本机访问相关 API</param>
5353 public static void AddAndInitDynamicApi ( this IServiceCollection services , IMvcBuilder builder ,
54- string docXmlPath , ApiRequestMethod defaultRequestMethod = ApiRequestMethod . Post , Type baseApiControllerType = null , int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null )
54+ string docXmlPath , ApiRequestMethod defaultRequestMethod = ApiRequestMethod . Post , Type baseApiControllerType = null , int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null , bool forbiddenExternalAccess = true )
5555 {
56- AddAndInitDynamicApi ( services , ( null , builder ) , docXmlPath , defaultRequestMethod , baseApiControllerType , taskCount , showDetailApiLog , copyCustomAttributes , additionalAttributeFunc ) ;
56+ AddAndInitDynamicApi ( services , ( null , builder ) , docXmlPath , defaultRequestMethod , baseApiControllerType , taskCount , showDetailApiLog , copyCustomAttributes , additionalAttributeFunc , forbiddenExternalAccess ) ;
5757 }
5858
5959 /// <summary>
@@ -68,9 +68,10 @@ public static void AddAndInitDynamicApi(this IServiceCollection services, IMvcBu
6868 /// <param name="taskCount"></param>
6969 /// <param name="additionalAttributes"></param>
7070 /// <param name="additionalAttributeFunc">是否复制自定义特性(AppBindAttribute 除外)</param>
71+ /// <param name="forbiddenExternalAccess">是否允许外部访问,默认为 false,只允许本机访问相关 API</param>
7172 private static void AddAndInitDynamicApi ( this IServiceCollection services , ( IMvcCoreBuilder coreBuilder , IMvcBuilder builder ) builder ,
7273 string docXmlPath , ApiRequestMethod defaultRequestMethod = ApiRequestMethod . Post , Type baseApiControllerType = null ,
73- int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null )
74+ int taskCount = 4 , bool showDetailApiLog = false , bool copyCustomAttributes = true , Func < MethodInfo , IEnumerable < CustomAttributeBuilder > > additionalAttributeFunc = null , bool forbiddenExternalAccess = true )
7475 {
7576 _ = defaultRequestMethod != ApiRequestMethod . GlobalDefault ? true : throw new Exception ( $ "{ nameof ( defaultRequestMethod ) } 不能作为默认请求类型!") ;
7677
@@ -79,7 +80,7 @@ private static void AddAndInitDynamicApi(this IServiceCollection services, (IMvc
7980
8081 WebApiEngine . AdditionalAttributeFunc = additionalAttributeFunc ;
8182
82- var webApiEngine = new WebApiEngine ( docXmlPath , defaultRequestMethod , baseApiControllerType , copyCustomAttributes , taskCount , showDetailApiLog ) ;
83+ var webApiEngine = new WebApiEngine ( docXmlPath , defaultRequestMethod , baseApiControllerType , copyCustomAttributes , taskCount , showDetailApiLog , forbiddenExternalAccess ) ;
8384
8485 bool preLoad = true ;
8586
0 commit comments