softlgl / Ocelot.Provider.Nacos

Repo for Nacos integration with Ocelot
72 stars 31 forks source link

我升级 nacos-sdk 到 1.3.5 修改源代码提示 Ocelot.Provider.Nacos.NacosClient.V2.RegSvcBgTask' has been registered #20

Open ganqiyin opened 1 year ago

ganqiyin commented 1 year ago

Microsoft.AspNetCore.Hosting.Diagnostics[6] Application startup exception System.AggregateException: One or more errors occurred. (No service for type 'Ocelot.Provider.Nacos.NacosClient.V2.RegSvcBgTask' has been registered.) ---> System.InvalidOperationException: No service for type 'Ocelot.Provider.Nacos.NacosClient.V2.RegSvcBgTask' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Ocelot.Provider.Nacos.NacosClient.V2.ServiceCollectionExtensions.UseNacosAspNet(IApplicationBuilder app, IHostApplicationLifetime lifetime, CancellationToken cancellationToken) in D:\SourceCode\Ocelot.Provider.Nacos\src\Ocelot.Provider.Nacos\NacosClient\V2\ServiceCollectionExtensions.cs:line 56 at Ocelot.Provider.Nacos.NacosMiddlewareConfigurationProvider.<>c.<.cctor>b3_0(IApplicationBuilder builder) in D:\SourceCode\Ocelot.Provider.Nacos\src\Ocelot.Provider.Nacos\NacosMiddlewareConfigurationProvider.cs:line 23 at Ocelot.Middleware.OcelotMiddlewareExtensions.CreateConfiguration(IApplicationBuilder builder) at Ocelot.Middleware.OcelotMiddlewareExtensions.UseOcelot(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration) at Ocelot.Middleware.OcelotMiddlewareExtensions.UseOcelot(IApplicationBuilder builder) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at ApiGatewayDemo.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in D:\SourceCode\Ocelot.Provider.Nacos\demo\ApiGatewayDemo\Startup.cs:line 50 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void* arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr args, BindingFlags invokeAttr) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisStartupFilter.<>c__DisplayClass0_0.b0(IApplicationBuilder builder) at Microsoft.WebTools.BrowserLink.Net.HostingStartup.<>cDisplayClass1_0.b0(IApplicationBuilder app) at Microsoft.AspNetCore.Watch.BrowserRefresh.HostingStartup.<>cDisplayClass1_0.b0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) Dispose

ganqiyin commented 1 year ago

地址 https://github.com/ganqiyin/Ocelot.Provider.Nacos/tree/master/src/Ocelot.Provider.Nacos

ganqiyin commented 1 year ago

把 AddHostService 改成 services.AddSingleton(); 是为啥?