/// <summary> /// 返回指定接口类型的实例(代理类,不需要实现) /// </summary> /// <param name="type"></param> /// <returns></returns> public static object GetProxy(Type type) { return(_feigns.GetOrAdd(type, typeInner => { if (!type.IsInterface) { throw new Exception("必须是非接口类型"); } var atts = TypeHelper.GetCustomAttributes <FeignClientAttribute>(type); if (atts.Count <= 0) { throw new Exception("未找到FeignClient特性配置"); } if (atts[0].Url == null || (atts[0].Url = atts[0].Url.Trim()).Length == 0) { throw new Exception("FeignClient特性配置Url不能为空"); } var feignAtt = atts[0]; var wrapper = new ProxyInvokeWrapper(); var ret = (FeignProcess)_factory.CreateProxy(typeof(FeignProcess), wrapper, type); if (feignAtt.Configuration == null) { ret.Config = new FeignDefaultConfig(); } else { ret.Config = (IFeignConfig)Activator.CreateInstance(feignAtt.Configuration); } ret.Url = feignAtt.Url; return ret; })); }
/// <summary> /// 创建指定接口和指定类的实例代理(代理类,不需要实现) /// </summary> /// <param name="interfaceType"></param> /// <param name="instanceType"></param> /// <returns></returns> public static object GetProxy(Type interfaceType, Type instanceType) { if (!interfaceType.IsInterface) { throw new Exception("必须是非接口类型"); } var wrapper = new ProxyInvokeWrapper(); return(_factory.CreateProxy(instanceType, wrapper, interfaceType)); }