Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMemoryCache();

            var proxyConfig        = Program.ProxyConfiguration.Get <ProxyConfig>();
            var proxyConfigService = new ProxyConfigService(proxyConfig);

            services.AddSingleton <IProxyConfigService, ProxyConfigService>((a) => proxyConfigService);
            services.AddSingleton <IProxyService, ProxyService>();

            proxyConfig.ServerUrls.ToList().ForEach(su => {
                services.AddHttpClient(su.Url)
                .ConfigurePrimaryHttpMessageHandler(h => {
                    return(new HttpClientHandler {
                        AllowAutoRedirect = false,
                        Credentials = proxyConfigService.GetCredentials(proxyConfigService.GetProxyServerUrlConfig((su.Url)))
                    });
                });
            });

            // If using IIS:
            services.Configure <IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Esempio n. 2
0
 public void ProxyConfigService_WhenCreatedWithout_HostingEnv_ShouldThrow()
 {
     var sut = new ProxyConfigService(null, "proxy.config.json");
 }