Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question regarding conventions and the Entity Framework scoped / async issue #231

Open
HaroldH76 opened this issue May 18, 2022 · 0 comments

Comments

@HaroldH76
Copy link

HaroldH76 commented May 18, 2022

We use GraphQL.Conventions and we have the issue that is described over here:
https://github.com/graphql-dotnet/graphql-dotnet/blob/master/docs2/site/docs/guides/known-issues.md#entity-framework-concurrency-issues

We would like to apply this suggestion:

Finally, you can create a scope within each field resolver that relies on Entity Framework or your other scoped services. Please see the section on this in the dependency injection documentation.

Are there any tips / examples / guidelines how this can be done with conventions and the inject attribute?

So basically what we need is that in each field we can create a new scope and derive our dependencies from there.
Currently we fixed it in the schema this way:

async Task<MyContent> Test([Inject] IServiceScopeFactory serviceScopeFactory)
{ 
  using var scope = serviceScopeFactory.CreateScope();
  var database = scope.GetService<MyDbContext>();
  return await database.MyContents.FirstAsync();
}

But would be nice if we can somehow change GraphQL conventions so that we can do this:

async Task<MyContent> Test([Inject] MyDbContext myDbContext)
{ 
  return await myDbContext.MyContents.FirstAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant