graphql-dotnet / graphql-dotnet/conventions
Question regarding conventions and the Entity Framework scoped / async issue
- Dominant language
- C#
- Stars
- 228
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/graphql-dotnet/graphql-dotnet/blob/master/docs2/site/docs/getting-started/dependency-injection.md#scoped-services-with-a-singleton-schema-lifetime).
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:
```cs
async Task Test([Inject] IServiceScopeFactory serviceScopeFactory)
{
using var scope = serviceScopeFactory.CreateScope();
var database = scope.GetService();
return await database.MyContents.FirstAsync();
}
```
But would be nice if we can somehow change GraphQL conventions so that we can do this:
```cs
async Task Test([Inject] MyDbContext myDbContext)
{
return await myDbContext.MyContents.FirstAsync();
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.