Skip to content

Commit e368b9f

Browse files
committed
IHttpApiClient空间变化
1 parent 7736631 commit e368b9f

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

Demo/HttpClients/IUserApi.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Net.Http;
1+
using System.Net.Http;
32
using System.Threading.Tasks;
43
using WebApiClient;
54
using WebApiClient.Attributes;
@@ -14,7 +13,7 @@ namespace Demo.HttpClients
1413
[LogFilter] // 记录请求日志
1514
[HttpHost("http://localhost:9999")] // HttpHost可以在Config传入覆盖
1615
[AutoReturn(EnsureSuccessStatusCode = true)]
17-
public interface IUserApi : IDisposable
16+
public interface IUserApi : IHttpApiClient
1817
{
1918
// GET {url}?account={account}&password={password}&something={something}
2019
[HttpGet]

WebApiClient/HttpApiClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public static int ConnectionLimit
7474
/// <returns></returns>
7575
public static TInterface Create<TInterface>() where TInterface : class, IDisposable
7676
{
77-
return Create<TInterface>(default(HttpApiConfig));
77+
var config = new HttpApiConfig();
78+
return Create<TInterface>(config);
7879
}
7980

8081
/// <summary>
@@ -101,6 +102,7 @@ public static TInterface Create<TInterface>(string httpHost) where TInterface :
101102
/// </summary>
102103
/// <typeparam name="TInterface">请求接口类型</typeparam>
103104
/// <param name="httpApiConfig">接口配置</param>
105+
/// <exception cref="ArgumentNullException"></exception>
104106
/// <exception cref="ArgumentException"></exception>
105107
/// <exception cref="NotSupportedException"></exception>
106108
/// <returns></returns>
@@ -122,7 +124,7 @@ public static object Create(Type interfaceType, HttpApiConfig httpApiConfig)
122124
{
123125
if (httpApiConfig == null)
124126
{
125-
httpApiConfig = new HttpApiConfig();
127+
throw new ArgumentNullException(nameof(httpApiConfig));
126128
}
127129

128130
var interceptor = new ApiInterceptor(httpApiConfig);

WebApiClient/Interfaces/IHttpApiClient.cs renamed to WebApiClient/IHttpApiClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
2+
using WebApiClient.Interfaces;
23

3-
namespace WebApiClient.Interfaces
4+
namespace WebApiClient
45
{
56
/// <summary>
67
/// 定义HttpApi客户端的接口

WebApiClient/Internal/TypeExtend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static void EnsureApiMethod(this MethodInfo method)
123123
var isTaskType = genericType == typeof(Task<>) || genericType == typeof(ITask<>);
124124
if (isTaskType == false)
125125
{
126-
var message = string.Format("接口{0}返回类型必须为Task<>或ITask<>", method.Name);
126+
var message = string.Format("返回类型必须为Task<>或ITask<>:{0}", method);
127127
throw new NotSupportedException(message);
128128
}
129129

0 commit comments

Comments
 (0)