File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ namespace WebApiClient
1414 /// </summary>
1515 static class HttpApiClientProxy
1616 {
17+ /// <summary>
18+ /// 同步锁
19+ /// </summary>
20+ private static readonly object syncRoot = new object ( ) ;
21+
1722 /// <summary>
1823 /// IApiInterceptor的Intercept方法
1924 /// </summary>
@@ -50,13 +55,15 @@ static class HttpApiClientProxy
5055 /// <returns></returns>
5156 public static object CreateProxyWithInterface ( Type interfaceType , IApiInterceptor interceptor )
5257 {
53- var apiMethods = interfaceType . GetAllApiMethods ( ) ;
54-
55- var proxyTypeCtor = proxyTypeCtorCache . GetOrAdd (
56- interfaceType ,
57- @interface => @interface . ImplementAsHttpApiClient ( apiMethods ) ) ;
58+ lock ( syncRoot )
59+ {
60+ var apiMethods = interfaceType . GetAllApiMethods ( ) ;
61+ var proxyTypeCtor = proxyTypeCtorCache . GetOrAdd (
62+ interfaceType ,
63+ @interface => @interface . ImplementAsHttpApiClient ( apiMethods ) ) ;
5864
59- return proxyTypeCtor . Invoke ( new object [ ] { interceptor , apiMethods } ) ;
65+ return proxyTypeCtor . Invoke ( new object [ ] { interceptor , apiMethods } ) ;
66+ }
6067 }
6168
6269 /// <summary>
You can’t perform that action at this time.
0 commit comments