public DefaultHttpProxyClientFactory( IHttpProxyDefinitionFactory definitionFactory, IHttpProxyFactory httpProxyFactory, IHttpProxyLoggerFactory loggerFactory, IHttpProxyFeatureProvider <IHttpProxyRotationFeature> rotationFeatureProvider, IHttpProxyFeatureProvider <IHttpProxyHealthCheckFeature> healthCheckFeatureProvider, IHttpProxyFeatureProvider <IHttpProxyRefill> proxyRefillFeatureProvider, IOptionsMonitor <HttpProxyClientFactoryOptions> optionsMonitor) { _loggerFactory = loggerFactory; _rotationFeatureProvider = rotationFeatureProvider; _healthCheckFeatureProvider = healthCheckFeatureProvider; _optionsMonitor = optionsMonitor; _proxyRefillFeatureProvider = proxyRefillFeatureProvider; _definitionFactory = definitionFactory; _httpProxyFactory = httpProxyFactory; _logger = loggerFactory.CreateLogger(typeof(DefaultHttpProxyClientFactory)); _clientStates = new ConcurrentDictionary <string, Lazy <HttpProxyClientState> >( StringComparer.InvariantCultureIgnoreCase); _lastAcquiredProxies = new ConcurrentDictionary <string, IHttpProxy>(StringComparer.InvariantCultureIgnoreCase); _deadHandlers = new ConcurrentQueue <DeadHandlerReference>(); _cleanupActivity = new HandlersCleanupActivity(DefaultCleanupPeriod, _deadHandlers, loggerFactory); _proxyDefinitions = new HashSet <HttpProxyDefinition>(); }
/// <summary> /// 添加一个客户端 /// </summary> /// <param name="type"></param> /// <returns></returns> public HttpProxyBuilder AddClientType(Type type) { services.AddTransient(type, sp => { IHttpProxyFactory factory = sp.GetService <IHttpProxyFactory>(); MethodInfo method = factory.GetType().GetMethod("Create").MakeGenericMethod(type); return(method.Invoke(factory, null)); }); MockAttribute mockAttr = type.GetCustomAttribute <MockAttribute>(); if (mockAttr != null) { services.AddSingleton(mockAttr.Type); } return(this); }
public ProxyRefillActivity( TimeSpan period, HttpProxyClientFactoryOptions options, IHttpProxyLoggerFactory loggerFactory, Func <IReadOnlyCollection <IHttpProxy> > aliveProxyAccessor, Action <IHttpProxy> proxyInsertCallback, IHttpProxyRefill proxyRefill, IHttpProxyFactory proxyFactory) : base(period, period, loggerFactory.CreateLogger(typeof(ProxyRefillActivity))) { _options = options; _aliveProxyAccessor = aliveProxyAccessor; _proxyInsertCallback = proxyInsertCallback; _proxyRefill = proxyRefill; _proxyFactory = proxyFactory; }