Different DI scope for controller and queries in graphql-dotnet?

461 Views Asked by At

I'm trying to implement a grahql-dotnet API. I'm running into some weird behavior when I try to pass a scoped object into my controller and the same object into some of my services used by the queries using dotnet core dependency injection.

It seems that there is a different DI scope being used when the DI instantiates the controller and when it's instantiating objects used by the queries, because two separate objects are being passed in this instance.

Is this expected behavior or is this something that can be avoided? I'm doing all of the same basic wiring for the controller and query as the star wars project.

Thanks in advance

1

There are 1 best solutions below

0
On

GraphTypes are created only once per schema, when the Schema is initialized. So any dependencies of your GraphTypes are also created only once per schema. Schema is best left as a singleton for now due to the cost of initialization, so all your GraphTypes and their dependencies are also effectively singletons where query execution is concerned.

At the time of writing there is an open issue to investigate resolving dependencies on a per-execution basis.