diff --git a/TmsRunner/Program.cs b/TmsRunner/Program.cs index afd88eb..b7afa05 100644 --- a/TmsRunner/Program.cs +++ b/TmsRunner/Program.cs @@ -91,72 +91,74 @@ private static IHostBuilder CreateHostBuilder(string[] args) outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.Console(LogEventLevel.Information)) - .ConfigureServices((_, services) => + .ConfigureServices((hostContext, services) => { - _ = (HostBuilderContext)services.AddHttpClient(nameof(HttpClientNames.Default), client => { - client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher; - client.DefaultRequestVersion = HttpVersion.Version11; - }) - .SetHandlerLifetime(TimeSpan.FromMinutes(20)) - .AddPolicyHandler(GetRetryPolicy()); - - _ = (HostBuilderContext)services - .AddSingleton(GetAdapterConfiguration(args)) - .AddSingleton(provider => + services.AddHttpClient(nameof(HttpClientNames.Default), client => { - var adapterConfig = provider.GetRequiredService(); - - return ConfigurationManager.Configure( - adapterConfig.ToInternalConfig(), - Path.GetDirectoryName(adapterConfig.TestAssemblyPath) ?? string.Empty - ); + client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher; + client.DefaultRequestVersion = HttpVersion.Version11; }) - .AddSingleton(provider => - { - var tmsSettings = provider.GetRequiredService(); + .SetHandlerLifetime(TimeSpan.FromMinutes(20)) + .AddPolicyHandler(GetRetryPolicy()); - return new TestIT.ApiClient.Client.Configuration + services + .AddSingleton(GetAdapterConfiguration(args)) + .AddSingleton(provider => { - BasePath = tmsSettings.Url ?? string.Empty, - ApiKeyPrefix = new Dictionary { { "Authorization", "PrivateToken" } }, - ApiKey = new Dictionary { { "Authorization", tmsSettings?.PrivateToken ?? string.Empty } } - }; - }) - .AddTransient(provider => new HttpClientHandler - { - ServerCertificateCustomValidationCallback = (_, _, _, _) => provider.GetRequiredService().CertValidation - }) - .AddTransient(provider => new AttachmentsApi( - provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), - provider.GetRequiredService(), - provider.GetRequiredService() - )) - .AddTransient(provider => new TestRunsApi( - provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), - provider.GetRequiredService(), - provider.GetRequiredService() - )) - .AddTransient(provider => new AutoTestsApi( - provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), - provider.GetRequiredService(), - provider.GetRequiredService() - )) - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient() - .AddTransient(provider => new AutoResetEvent(false)) - .AddTransient() - .AddTransient() - .AddTransient(provider => new VsTestConsoleWrapper( - provider.GetRequiredService().RunnerPath ?? string.Empty, - new ConsoleParameters { LogFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"log.txt") } - )) - .AddSingleton(); + var adapterConfig = provider.GetRequiredService(); + + return ConfigurationManager.Configure( + adapterConfig.ToInternalConfig(), + Path.GetDirectoryName(adapterConfig.TestAssemblyPath) ?? string.Empty + ); + }) + .AddSingleton(provider => + { + var tmsSettings = provider.GetRequiredService(); + + return new TestIT.ApiClient.Client.Configuration + { + BasePath = tmsSettings.Url ?? string.Empty, + ApiKeyPrefix = new Dictionary { { "Authorization", "PrivateToken" } }, + ApiKey = new Dictionary { { "Authorization", tmsSettings?.PrivateToken ?? string.Empty } } + }; + }) + .AddTransient(provider => new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (_, _, _, _) => provider.GetRequiredService().CertValidation + }) + .AddTransient(provider => new AttachmentsApi( + provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), + provider.GetRequiredService(), + provider.GetRequiredService() + )) + .AddTransient(provider => new TestRunsApi( + provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), + provider.GetRequiredService(), + provider.GetRequiredService() + )) + .AddTransient(provider => new AutoTestsApi( + provider.GetRequiredService().CreateClient(nameof(HttpClientNames.Default)), + provider.GetRequiredService(), + provider.GetRequiredService() + )) + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient(provider => new AutoResetEvent(false)) + .AddTransient() + .AddTransient() + .AddTransient(provider => new VsTestConsoleWrapper( + provider.GetRequiredService().RunnerPath ?? string.Empty, + new ConsoleParameters { LogFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"log.txt") } + )) + .AddSingleton(); + } }); }