From beb14d06249bee81c433344d55414e5ad5a309ae Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Mon, 29 Jan 2024 17:29:36 -0800 Subject: [PATCH] Support keyed service collection (#360) * Bump up dependency injection package * Support keyed services in the service container --- .../ApplicationInsights.Kubernetes.csproj | 4 ++-- .../Extensions/ApplicationInsightsExtensions.cs | 2 +- src/ApplicationInsights.Kubernetes/K8sInfoBootstrap.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ApplicationInsights.Kubernetes/ApplicationInsights.Kubernetes.csproj b/src/ApplicationInsights.Kubernetes/ApplicationInsights.Kubernetes.csproj index 98fe4ff..01436ab 100644 --- a/src/ApplicationInsights.Kubernetes/ApplicationInsights.Kubernetes.csproj +++ b/src/ApplicationInsights.Kubernetes/ApplicationInsights.Kubernetes.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs b/src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs index 94ae6da..df3f070 100644 --- a/src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs +++ b/src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs @@ -65,7 +65,7 @@ public static void StartApplicationInsightsKubernetesEnricher(this IServiceProvi /// /// The service collection. private static bool KubernetesTelemetryInitializerExists(IServiceCollection serviceCollection) - => serviceCollection.Any(t => t.ImplementationType == typeof(KubernetesTelemetryInitializer)); + => serviceCollection.Any(t => !t.IsKeyedService && t.ImplementationType == typeof(KubernetesTelemetryInitializer)); /// /// Configure the KubernetesTelemetryInitializer and its dependencies. diff --git a/src/ApplicationInsights.Kubernetes/K8sInfoBootstrap.cs b/src/ApplicationInsights.Kubernetes/K8sInfoBootstrap.cs index 3a82c6d..ee80717 100644 --- a/src/ApplicationInsights.Kubernetes/K8sInfoBootstrap.cs +++ b/src/ApplicationInsights.Kubernetes/K8sInfoBootstrap.cs @@ -14,7 +14,7 @@ internal class K8sInfoBootstrap : IK8sInfoBootstrap private readonly AppInsightsForKubernetesOptions _options; - private readonly object _locker = new object(); + private readonly object _locker = new(); private readonly IServiceScopeFactory _serviceScopeFactory; private bool _hasExecuted = false; private readonly ExponentialDelaySource _exponentialDelaySource;