1
votes

I'm attempting to integrate GrapQL.EntityFramework using a DB first approach on an Azure Function. I've generated the needed contexts, User graphs, query, along with the function itself. Currently I'm having an issue with the Startup file of my function app where I am to use dependency injection.

I've attempted both options on the configuration guide in the GraphQL.EntityFramework Docs. I've also made attempts at snippets of code such as builder.Services.AddSingleton(typeof(IEfGraphQLService<PersonarDBContext>),instance => { return new DBContext(); });

The current state of my startup file

public override void Configure(IFunctionsHostBuilder builder)
{
     string connection = ""
     builder.Services.AddTransient<UserQuery>();
     builder.Services.AddDbContext<DBContext>(options => options.UseSqlServer(connection));
     var optionBuilder = new DbContextOptionsBuilder<DBContext>();
     optionBuilder.UseSqlServer(connection);
     EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
     EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);
     builder.Services.AddSingleton(typeof(IEfGraphQLService<DBContext>),instance => { return new DBContext(); });
}

At this point in time I am just attempting to get my function app to startup properly. I am currently experiencing this error output.

User: Microsoft.Azure.WebJobs.Host: Error indexing method 'User'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'service' to type IEfGraphQLService`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

1
you are trying to match differing types here builder.Services.AddSingleton(typeof(IEfGraphQLService<DBContext>),instance => { return new DBContext(); });. Does DbContext derive from IEfGraphQLService<DBContext>? I highly doubt.Nkosi
@Nkosi DB context isn't derived from the IEfGraphQLService, it uses the EntityFramework.Core DbContextJacq
On removal of the last line I still receive the same error outputJacq

1 Answers

0
votes

Likely worth opening an issue on GitHub but my suspicion is whatever the library is trying to auto-register here is throwing the exception

EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
 EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);