我正在使用这个包:Microsoft.ApplicationInsights.Kubernetes.HostingStartup
. 这是使用 ASP.NET Core 的托管启动功能来注册应用程序洞察力。如果项目是带有控制器的 Web api,它工作正常,但在尝试使用最少的 API 时出现异常:
Unhandled exception. System.InvalidOperationException: No service for type 'Microsoft.Extensions.Configuration.IConfiguration' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.Options.OptionsBuilder`1.<>c__DisplayClass9_0`1.<Configure>b__0(IServiceProvider sp)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverCo
ntext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverC
ontext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverC
ontext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.BuildK8sServiceCollection(IServiceCollection services, Func`1 detectKubernetes, IK
ubernetesServiceCollectionBuilder kubernetesServiceCollectionBuilder)
at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.ConfigureKubernetesTelemetryInitializer(IServiceCollection serviceCollection, Func
`1 detectKubernetes, IKubernetesServiceCollectionBuilder kubernetesServiceCollectionBuilder, Action`1 applyOptions)
at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsKubernetesEnricher(IServiceCollection services, Action`1 app
lyOptions, IKubernetesServiceCollectionBuilder kubernetesServiceCollectionBuilder, Func`1 detectKubernetes)
at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsKubernetesEnricher(IServiceCollection services, Action`1 app
lyOptions)
at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsKubernetesEnricher(IServiceCollection services)
at ApplicationInsights.Kubernetes.HostingStartup.K8sInjection.<>c.<Configure>b__0_0(WebHostBuilderContext cxt, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<.ctor>b__6_2(HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.BootstrapHostBuilder.RunDefaultCallbacks(ConfigurationManager configuration, HostBuilder innerBuilder)
at Microsoft.AspNetCore.Builder.WebApplicationBuilder..ctor(WebApplicationOptions options, Action`1 configureDefaults)
at Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(String[] args)
是否可以使用最少的 API 和托管启动?