1

为了提供更多上下文,我们有一个带有 GraphQL 设置的 ASP.NET Core abp 框架。一切正常,但是当我们在带有负载平衡器的环境中部署它时,它会失败并出现以下错误。

错误

    Object name: 'Scope cache was already disposed. This is most likely a bug in the calling code.'.
   at Castle.MicroKernel.Lifestyle.Scoped.ScopeCache.get_Item(Object id)
   at Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance)
   at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
   at Castle.Windsor.MsDependencyInjection.MsScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext)
   at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional)
   at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetService(Type serviceType)
   at GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) in C:\projects\graphql-dotnet\src\GraphQL\Utilities\ServiceProviderExtensions.cs:line 38
   at GraphQL.Types.Schema.<CreateTypesLookup>b__68_1(Type type) in C:\projects\graphql-dotnet\src\GraphQL\Types\Schema.cs:line 314
   at GraphQL.Types.GraphTypesLookup.AddTypeIfNotRegistered(Type type, TypeCollectionContext context) in C:\projects\graphql-dotnet\src\GraphQL\Types\GraphTypesLookup.cs:line 407
   at GraphQL.Types.GraphTypesLookup.HandleField(IComplexGraphType parentType, FieldType field, TypeCollectionContext context, Boolean applyNameConverter) in C:\projects\graphql-dotnet\src\GraphQL\Types\GraphTypesLookup.cs:line 332
   at GraphQL.Types.GraphTypesLookup.AddType(IGraphType type, TypeCollectionContext context) in C:\projects\graphql-dotnet\src\GraphQL\Types\GraphTypesLookup.cs:line 246
   at GraphQL.Types.GraphTypesLookup.Create(IEnumerable`1 types, IEnumerable`1 directives, Func`2 resolveType, INameConverter nameConverter, Boolean seal) in C:\projects\graphql-dotnet\src\GraphQL\Types\GraphTypesLookup.cs:line 88
   at GraphQL.Types.Schema.CreateTypesLookup() in C:\projects\graphql-dotnet\src\GraphQL\Types\Schema.cs:line 311
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location where exception was thrown ---
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GraphQL.Types.Schema.FindType(String name) in C:\projects\graphql-dotnet\src\GraphQL\Types\Schema.cs:line 231
   at GraphQL.Types.Schema.Initialize() in C:\projects\graphql-dotnet\src\GraphQL\Types\Schema.cs:line 78
   at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options) in C:\projects\graphql-dotnet\src\GraphQL\Execution\DocumentExecuter.cs:line 66

我们像下面这样设置 Startup.cs

services.AddSingleton<IDocumentWriter, DocumentWriter>();
        services.AddSingleton<IDocumentExecuter, DocumentExecuter>();
        services.AddSingleton<IDataLoaderContextAccessor, DataLoaderContextAccessor>();
        services.AddSingleton<DataLoaderDocumentListener>();
        services.AddSingleton<ISchema, SchoolSchema>();
        services.AddSingleton<SchoolSchema>();
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        services.AddSingleton<SchoolQuery>();
        services.AddSingleton<SchoolMutation>();
        services.AddSingleton<IHttpHandler,HttpHandler>();
        services.AddSingleton<HttpClient>();

        services.AddScoped<StudentTypeCollection>();
4

0 回答 0