ConfigureServices
services.AddSingleton<IServiceProvider>(c => new FuncServiceProvider(type => c.GetRequiredService(type)));
services.AddDbContext<Context>(options => options.UseSqlServer(configuration.GetConnectionString("Default")));
services.AddSingleton<Query>();
services.AddSingleton<Schema>();
services.AddGraphQL();
Configure
app.UseGraphQL<Schema>();
Query
public class Query : ObjectGraphType
{
public Query(IServiceProvider resolver)
{
var db = resolver.GetRequiredService<Context>();
Name = "query";
Field<ListGraphType<Types.Note>>("notes", resolve: _ => db.Notes.AsAsyncEnumerable());
}
}
executing the GraphQL endpoint results in the following exception
System.InvalidOperationException: Cannot resolve scoped service 'Models.Database.Context' from root provider.
some more details.