Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core 无法解析类型为';xxxSchema';试图激活';GraphQL.Server.Internal.DefaultGraphQLExecuter_.net Core_Dependency Injection_Graphql - Fatal编程技术网

.net core 无法解析类型为';xxxSchema';试图激活';GraphQL.Server.Internal.DefaultGraphQLExecuter

.net core 无法解析类型为';xxxSchema';试图激活';GraphQL.Server.Internal.DefaultGraphQLExecuter,.net-core,dependency-injection,graphql,.net Core,Dependency Injection,Graphql,我正在按照示例创建GraphQL,但在转到我的http://localhost:5001/graphql. 我已经讨论了asp.core DependencyInjections的许多方面,但仍然返回到这个错误: System.InvalidOperationException: Unable to resolve service for type 'MyProject.GraphQL.MySchema' while attempting to activate 'GraphQL.Ser

我正在按照示例创建GraphQL,但在转到我的http://localhost:5001/graphql.

我已经讨论了asp.core DependencyInjections的许多方面,但仍然返回到这个错误:

    System.InvalidOperationException: Unable to resolve service for type 'MyProject.GraphQL.MySchema' while attempting to activate 'GraphQL.Server.Internal.DefaultGraphQLExecuter`1[MyProject.GraphQL.MySchema]'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot, Boolean throwOnConstraintViolation)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.<>c__DisplayClass7_0.<GetCallSite>b__0(Type type)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware`1.InvokeAsync(HttpContext context) in /_/src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 136
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
System.InvalidOperationException:尝试激活“GraphQL.Server.Internal.DefaultGraphQLExecuter`1[MyProject.GraphQL.MySchema]”时,无法解析类型“MyProject.GraphQL.MySchema”的服务。
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(类型serviceType,类型implementationType,CallSiteChain CallSiteChain,ParameterInfo[]参数,布尔throwIfCallSiteNotFound)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(结果缓存生存期,类型serviceType,类型implementationType,CallSiteChain CallSiteChain)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor描述符,类型serviceType,CallSiteChain CallSiteChain,Int32插槽,布尔throwOnConstraintViolation)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(类型serviceType,CallSiteChain CallSiteChain)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(类型serviceType,CallSiteChain CallSiteChain)
在Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.c__DisplayClass7_0.b__0(类型)
位于System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey,Func`2 valueFactory)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(类型serviceType,CallSiteChain CallSiteChain)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(类型serviceType)
位于System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey,Func`2 valueFactory)
在Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(输入serviceType,ServiceProviderEngineScope ServiceProviderEngineScope)
位于Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(类型serviceType)
位于Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider提供程序,键入serviceType)
位于Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider提供程序)
在/u/src/Transports.AspNetCore/GraphQLHttpMiddleware.cs中的GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware`1.InvokeAsync(HttpContext上下文):第136行
位于Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文)
有人能给我指出正确的方向来解决这个问题吗 .Net核心5.0; 最新Nuget GraphQL.Net服务器

我的Startup.cs代码是

using GraphQL;
using GraphQL.Server;
using GraphQL.SystemTextJson;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace Ace.Aceterilize
{
    public class Startup
    {
        public Startup(IConfiguration configuration, IWebHostEnvironment environment)
        {
            Configuration = configuration;
            Environment = environment;
        }

        public IConfiguration Configuration { get; }

        public IWebHostEnvironment Environment { get; }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<MyDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Singleton);

            services.AddHttpContextAccessor();
            //GraphQL
            services.AddSingleton<IDocumentExecuter, DocumentExecuter>();
            services.AddSingleton<IDocumentWriter, DocumentWriter>();

            services.AddSingleton<MyQuery>();
            services.AddSingleton<ISchema, MySchema>();

            services.AddGraphQL((options, provider) =>
        {
            options.EnableMetrics = Environment.IsDevelopment();
            var logger = provider.GetRequiredService<ILogger>();
            options.UnhandledExceptionDelegate = ctx => logger.Error("GraphQL: {Error} occurred", ctx.OriginalException.Message);
        })
         // Add required services for GraphQL request/response de/serialization
        .AddSystemTextJson(configureDeserializerSettings => { }, configureSerializerSettings => { })
        .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
        .AddWebSockets() // Add required services for web socket support
        .AddDataLoader() // Add required services for DataLoader support
        .AddGraphTypes(typeof(AceteriliseSchema), ServiceLifetime.Transient);

            services.AddControllersWithViews();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
 //... Standard if development Mode
            }

            app.UseWebSockets();
            app.UseGraphQL<MySchema, GraphQLHttpMiddlewareWithLogs<MySchema>>();
            app.UseGraphQLWebSockets<MySchema>();
            // use graphiQL middleware at default path /ui/graphiql
            app.UseGraphiQLServer();

            // use graphql-playground middleware at default path /ui/playground
            app.UseGraphQLPlayground();

            // use altair middleware at default path /ui/altair
            app.UseGraphQLAltair();

            // use voyager middleware at default path /ui/voyager
            app.UseGraphQLVoyager();

          
        }
    }
}
使用GraphQL;
使用GraphQL.Server;
使用GraphQL.SystemTextJson;
使用GraphQL.Types;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.EntityFrameworkCore;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Hosting;
使用Serilog;
命名空间Ace.aceterize
{
公营创业
{
公共启动(IConfiguration配置、IWebHostEnvironment环境)
{
配置=配置;
环境=环境;
}
公共IConfiguration配置{get;}
公共IWebHostEnvironment环境{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”))、ServiceLifetime.Singleton);
AddHttpContextAccessor();
//图形ql
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddGraphQL((选项,提供者)=>
{
options.EnableMetrics=Environment.IsDevelopment();
var logger=provider.GetRequiredService();
options.UnhandledExceptionDelegate=ctx=>logger.Error(“GraphQL:{Error}发生”,ctx.OriginalException.Message);
})
//添加GraphQL请求/响应反序列化/序列化所需的服务
.AddSystemTextJson(configureDeserializerSettings=>{},configureSerializerSettings=>{})
.AddErrorInfoProvider(opt=>opt.exposeeExceptionsTackTrace=Environment.IsDevelopment())
.AddWebSockets()//添加web套接字支持所需的服务
.AddDataLoader()//为DataLoader支持添加所需的服务
.AddGraphTypes(typeof(AceteriliseSchema),ServiceLifetime.Transient);
services.AddControllersWithViews();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
//…标准if开发模式
}
app.UseWebSockets();
app.UseGraphQL();
app.UseGraphQLWebSockets();
//使用默认路径/ui/graphiQL的graphiQL中间件
app.UseGraphiQLServer();
//在默认路径/ui/playerly处使用graphql游乐场中间件
app.usegraphqlplayde();
//在默认路径/ui/altair下使用altair中间件
app.UseGraphQLAltair();
//用voya
  public class MySchema : Schema,ISchema
    {
        public MySchema(IServiceProvider provider):base(provider)
        {
            {
                Query = provider.GetRequiredService<MyQuery>();
          
            }
        }
    }
 public class MyQuery : ObjectGraphType
    {
        public MyQuery(MyDbContext db)
        {

            Field<ListGraphType<ApplicationUserType>>("users", "List of Active Users",
                  
                resolve: context => db.ApplicationUsers.Where(u => !u.IsDeleted));
        }
    }

  public class ApplicationUserType : ObjectGraphType<ApplicationUser>
    {
        public ApplicationUserType()
        {
            Field(t => t.Id);
            Field(t => t.UserName);
}}}
services.AddSingleton<ISchema, MySchema>();
services.AddSingleton<MySchema>();