/// <summary> /// 导出远程调用的依赖项。 /// </summary> /// <returns></returns> public IEnumerable <SmartServiceDescriptor> ExportDependencies(SwiftyOptions swiftyOptions) { var thriftServices = this.RawAssembly.ExportedTypes .Where(t => t.GetTypeInfo().IsInterface&& IsThriftService(t)); Object GetRemoteServiceInstance(IServiceProvider serviceProvider, RemoteServiceAttribute removeAttribute, Type thriftInterface) { var clientManager = serviceProvider.GetRequiredService <SwiftyClientManager>(); ClientSslConfig ssl = swiftyOptions.Client.GetSslConfig(removeAttribute.VipAddress); if (this._options.Client.TryGetDirectAddress(removeAttribute.VipAddress, out string address)) { return(clientManager.Client.Create(thriftInterface, address, ssl)); } return(clientManager.Client.Create(thriftInterface, removeAttribute.Version, removeAttribute.VipAddress, ssl)); } foreach (var thriftService in thriftServices) { if (thriftService.TryGetRemoteServiceAttribute(true, out RemoteServiceAttribute attribute)) { yield return(new SmartServiceDescriptor(thriftService, sp => GetRemoteServiceInstance(sp, attribute, thriftService), ServiceLifetime.Singleton) { Options = SmartOptions.TryAppend }); } } }
public RemoteDependencyAssembly(SwiftyOptions options, Assembly assembly) { _options = options; this.RawAssembly = assembly; }