prefer transient registration

This commit is contained in:
Collin M. Barrett 2019-07-13 14:26:41 -05:00
parent e200bad9e5
commit 2f86f635ac
2 changed files with 5 additions and 4 deletions

View file

@ -9,7 +9,7 @@ public static class ServiceCollectionExtensions
{
public static void AddApplicationInsights(this IServiceCollection services)
{
services.AddSingleton(b =>
services.AddTransient(b =>
{
var applicationInsightsSettings = b.GetService<IOptions<ApplicationInsightsSettings>>().Value;
return new TelemetryConfiguration
@ -19,8 +19,8 @@ public static void AddApplicationInsights(this IServiceCollection services)
});
services.AddSingleton(b =>
{
var configuration = b.GetService<TelemetryConfiguration>();
return new AgentTelemetryClient(configuration);
var telemetryConfiguration = b.GetService<TelemetryConfiguration>();
return new AgentTelemetryClient(telemetryConfiguration);
});
services.AddSingleton(b =>
{

View file

@ -27,7 +27,8 @@ await Task.Run(() =>
var logger = services.BuildServiceProvider().GetService<ILogger<IPolicyRegistry<string>>>();
logger.LogInformation("Retrying after 429 TooManyRequests",
response.Result.RequestMessage.RequestUri,
response.Result?.Headers.RetryAfter.Delta.ToString(), retryCount);
response.Result?.Headers.RetryAfter.Delta.ToString(),
retryCount);
});
});
registry.Add(nameof(waitAndRetryTooManyRequests), waitAndRetryTooManyRequests);