Можно ли использовать стартовые сборки хостинга с минимальными API?

Я использую этот пакет: . Это использует функциональные возможности запуска хостинга для ASP.NET Core для регистрации аналитических сведений о приложении. Он отлично работает, если проект представляет собой веб-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 и запуск хостинга?

1 ответ

Похоже, проблема была в самом пакете. Я обновил пакет до версии 2.0.2-beta2. Кажется, теперь все работает нормально.

Другие вопросы по тегам