/// <summary> /// 创建ApiTaskOf(T)的实例 /// </summary> /// <param name="httpApiConfig">http接口配置</param> /// <param name="apiActionDescriptor">api描述</param> /// <returns></returns> public static ApiTask CreateInstance(DcpApiConfig httpApiConfig, ApiActionDescriptor apiActionDescriptor) { // var instance = new ApiTask<TResult>(httpApiConfig, apiActionDescriptor); var ctor = apiActionDescriptor.Return.ITaskCtor; return(ctor.Invoke(new object[] { httpApiConfig, apiActionDescriptor }) as ApiTask); }
/// <summary> /// 创建实现了指定接口的HttpApiClient实例 /// </summary> /// <param name="interfaceType">请求接口类型</param> /// <param name="httpApiConfig">接口配置</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="TypeLoadException"></exception> /// <returns></returns> public static object Create(Type interfaceType, DcpApiConfig httpApiConfig) { if (httpApiConfig == null) { throw new ArgumentNullException(nameof(httpApiConfig)); } var interceptor = new ApiInterceptor(httpApiConfig); return(Create(interfaceType, interceptor)); }
/// <summary> /// 创建实现了指定接口的HttpApiClient实例 /// </summary> /// <typeparam name="TInterface">请求接口类型</typeparam> /// <param name="httpHost">Http服务完整主机域名,如http://www.webapiclient.com</param> /// <exception cref="ArgumentException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="UriFormatException"></exception> /// <exception cref="TypeLoadException"></exception> /// <returns></returns> public static TInterface Create <TInterface>(string httpHost) where TInterface : class, IDcpApi { var config = new DcpApiConfig(); config.BatInitProperty(_DefaultConfig); if (string.IsNullOrEmpty(httpHost) == false) { config.HttpHost = new Uri(httpHost, UriKind.Absolute); } return(Create <TInterface>(config)); }
/// <summary> /// 创建实现了指定接口的HttpApiClient实例 /// </summary> /// <typeparam name="TInterface">请求接口类型</typeparam> /// <exception cref="ArgumentException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="TypeLoadException"></exception> /// <returns></returns> public static TInterface Create <TInterface>(bool isForceProxy = false) where TInterface : class, IDcpApi { var config = new DcpApiConfig(); config.BatInitProperty(_DefaultConfig); if (!isForceProxy) { var dcpService = IocUnity.Get <TInterface>(); if (dcpService != null) { return(dcpService); } } return(Create <TInterface>(config)); }
public static void Init(DcpApiConfig dcpApiConfig) { lock (_lockObj) { if (IsInitSuccess) { return; } _DefaultConfig = dcpApiConfig; if (_DefaultConfig == null) { _DefaultConfig = new DcpApiConfig(); } if (string.IsNullOrEmpty(_DefaultConfig.Exchange)) { throw new ArgumentNullException("Exhange交换机值不能为空!"); } if (string.IsNullOrEmpty(_DefaultConfig.MqAddress)) { throw new ArgumentNullException("MqAddress不能为空!"); } IsInitSuccess = true; } }
/// <summary> /// http接口调用的拦截器 /// </summary> /// <param name="httpApiConfig">httpApi配置</param> /// <exception cref="ArgumentNullException"></exception> public ApiInterceptor(DcpApiConfig apiConfig) { this.ApiConfig = apiConfig ?? throw new ArgumentNullException(nameof(ApiConfig)); }
public static void BatInitProperty(this DcpApiConfig dcpApiConfig, DcpApiConfig dcpApiConfigNew) { dcpApiConfig.Exchange = dcpApiConfigNew.Exchange; dcpApiConfig.MqAddress = dcpApiConfigNew.MqAddress; dcpApiConfig.TimeOut = dcpApiConfigNew.TimeOut; }
/// <summary> /// Api请求的异步任务 /// </summary> /// <param name="httpApiConfig">http接口配置</param> /// <param name="apiActionDescriptor">api描述</param> public ApiTaskOf(DcpApiConfig httpApiConfig, ApiActionDescriptor apiActionDescriptor) { this.ApiConfig = httpApiConfig; this.apiActionDescriptor = apiActionDescriptor; }
/// <summary> /// 创建实现了指定接口的HttpApiClient实例 /// </summary> /// <typeparam name="TInterface">请求接口类型</typeparam> /// <param name="httpApiConfig">接口配置</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="TypeLoadException"></exception> /// <returns></returns> public static TInterface Create <TInterface>(DcpApiConfig dcpApiConfig) where TInterface : class, IDcpApi { return(Create(typeof(TInterface), dcpApiConfig) as TInterface); }