To give more context we have a ASP.NET Core abp framework with GraphQL setup. It is all working good but when we deploy this in the environment with load balancer it is failing with error below.
Error
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
We setup out Startup.cs like below
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>();