示例#1
0
        /// <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));
        }
示例#2
0
        /// <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));
        }