You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Microsoft.ApplicationInsights.WorkerService Version 2.22.0
Microsoft.Extensions.DependencyInjection 9.0.1
.NET 8
Windows, but reproducible within an MSTest project.
Describe the bug
Not all the applicationinsights dependencies are added to DI if there has been a Keyed service registered before calling the AddApplicationInsightsTelemetryWorkerService extension method. This causes many exceptions at runtime when you would expect the services to have been added. I ran into a DI issue stating that the TelemetryClient was not registered but there is more missing that just this client.
To Reproduce
Create blank MSTest project and add dependencies listed above.
Implement the following test:
usingMicrosoft.Extensions.DependencyInjection;namespaceTestProject1{[TestClass]publicclassUnitTest1{[TestMethod]publicvoidTestMethod1(){varservices1=newServiceCollection();varservices2=newServiceCollection();services1.AddApplicationInsightsTelemetryWorkerService();services1.AddKeyedScoped<ICalculator,LoggingCalculator>("key1");services2.AddKeyedScoped<ICalculator,QuietCalculator>("key2");services2.AddApplicationInsightsTelemetryWorkerService();// Fails because services1.Count is 32 and services2.Count is 5Assert.Equals(services1.Count,services2.Count);}}publicinterfaceICalculator{intSum(inta,intb);}publicclassLoggingCalculator:ICalculator{publicintSum(inta,intb){Console.WriteLine($"Sum of {a} and {b} is {a+b}");returna+b;}}publicclassQuietCalculator:ICalculator{publicintSum(inta,intb){returna+b;}}}
The text was updated successfully, but these errors were encountered:
victorhubbers
changed the title
Inconsistent and unexpected behaviour in AddApplicationInsightsTelemetryWorkerService when a Keyed service has been added previously
Buggy behaviour in AddApplicationInsightsTelemetryWorkerService when a Keyed service has been added previously
Jan 17, 2025
Describe the bug
Not all the applicationinsights dependencies are added to DI if there has been a Keyed service registered before calling the
AddApplicationInsightsTelemetryWorkerService
extension method. This causes many exceptions at runtime when you would expect the services to have been added. I ran into a DI issue stating that theTelemetryClient
was not registered but there is more missing that just this client.To Reproduce
The text was updated successfully, but these errors were encountered: