@@ -11,7 +11,7 @@ namespace WebApiClient
1111 /// 提供HttpApi的配置注册和实例创建
1212 /// 并对实例的生命周期进行自动管理
1313 /// </summary>
14- public class HttpApiFactory < TInterface > : IHttpApiFactory < TInterface > , _IHttpApiFactory
14+ public class HttpApiFactory < TInterface > : IHttpApiFactory < TInterface > , IHttpApiFactory
1515 where TInterface : class , IHttpApi
1616 {
1717 /// <summary>
@@ -34,24 +34,30 @@ public class HttpApiFactory<TInterface> : IHttpApiFactory<TInterface>, _IHttpApi
3434 /// </summary>
3535 private TimeSpan cleanupInterval = TimeSpan . FromSeconds ( 10d ) ;
3636
37+ /// <summary>
38+ /// 过期的记录
39+ /// </summary>
40+ private readonly ConcurrentQueue < ExpiredEntry > expiredEntries = new ConcurrentQueue < ExpiredEntry > ( ) ;
41+
3742 /// <summary>
3843 /// 激活的记录
3944 /// </summary>
4045 private volatile Lazy < ActiveEntry > activeEntryLazy ;
4146
47+
4248 /// <summary>
43- /// 过期的记录
49+ /// 获取生命周期
4450 /// </summary>
45- private readonly ConcurrentQueue < ExpiredEntry > expiredEntries ;
46-
51+ TimeSpan IHttpApiFactory . Lifetime
52+ {
53+ get => this . lifeTime ;
54+ }
4755
4856 /// <summary>
4957 /// HttpApi创建工厂
5058 /// </summary>
5159 public HttpApiFactory ( )
5260 {
53- this . expiredEntries = new ConcurrentQueue < ExpiredEntry > ( ) ;
54-
5561 this . activeEntryLazy = new Lazy < ActiveEntry > (
5662 this . CreateActiveEntry ,
5763 LazyThreadSafetyMode . ExecutionAndPublication ) ;
@@ -118,14 +124,14 @@ public HttpApiFactory<TInterface> ConfigureHttpApiConfig(Action<HttpApiConfig> c
118124 /// <returns></returns>
119125 public TInterface CreateHttpApi ( )
120126 {
121- return ( ( _IHttpApiFactory ) this ) . CreateHttpApi ( ) as TInterface ;
127+ return ( ( IHttpApiFactory ) this ) . CreateHttpApi ( ) as TInterface ;
122128 }
123129
124130 /// <summary>
125131 /// 创建接口的代理实例
126132 /// </summary>
127133 /// <returns></returns>
128- object _IHttpApiFactory . CreateHttpApi ( )
134+ object IHttpApiFactory . CreateHttpApi ( )
129135 {
130136 var interceptor = this . activeEntryLazy . Value . Interceptor ;
131137 return HttpApiClient . Create ( typeof ( TInterface ) , interceptor ) ;
@@ -157,7 +163,7 @@ private ActiveEntry CreateActiveEntry()
157163 /// 当有记录失效时
158164 /// </summary>
159165 /// <param name="active">激活的记录</param>
160- void _IHttpApiFactory . OnEntryDeactivate ( ActiveEntry active )
166+ void IHttpApiFactory . OnEntryDeactivate ( ActiveEntry active )
161167 {
162168 // 切换激活状态的记录的实例
163169 this . activeEntryLazy = new Lazy < ActiveEntry > (
@@ -168,13 +174,6 @@ void _IHttpApiFactory.OnEntryDeactivate(ActiveEntry active)
168174 this . expiredEntries . Enqueue ( expired ) ;
169175 }
170176
171- /// <summary>
172- /// 获取生命周期
173- /// </summary>
174- TimeSpan _IHttpApiFactory . Lifetime
175- {
176- get => this . lifeTime ;
177- }
178177
179178 /// <summary>
180179 /// 注册清理任务
@@ -209,6 +208,5 @@ private void CleanupCallback()
209208
210209 this . RegisteCleanup ( ) ;
211210 }
212-
213211 }
214212}
0 commit comments