-
-
Notifications
You must be signed in to change notification settings - Fork 748
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
Azure Function DI Null Exception #1305
Comments
#520 links to supplied example repo and suggests that there will be native support. @michaelstaib you mention there will be native support in version 11. How far off is this likely to be? and do you have any working examples that I could use? |
@OneCyrus had similar issue, maybe he knows more |
the problem is likely the scoped DI which has a different lifetime in AzF: https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#service-lifetimes |
we discussed this here: https://hotchocolategraphql.slack.com/archives/CD9TNKT8T/p1569335037212400 |
I dont have access to Slack. Could you provide a quick summary? Is it an issue with how HC adds the GraphQL services during Configure? |
i just gave this one a try again. and it doesn't look like the azure functions DI behaves incorrectly. the scoped instances are created correctly. there's also a sample on the AzF repo which shows this: https://github.com/Azure/azure-functions-dotnet-extensions/tree/master/src/samples/DependencyInjection/Scopes it looks like there's really an issue where hotchocolate behaves strange in combination with AzF DI. |
Hm... @michaelstaib could this be related to the custom service factory? Somehow loosing state |
I think the issue is how we build the execution builder. We will fix that in 11 since we will take apart the whole execution. But first I want to focus more on StrawberryShake and Visual Studio integration. Once Rafi is done with the first public preview of bcp we can start work on this. |
Ok. So @OneCyrus and I were debugging a bit. The DI containers fails when it tries to inject This behavior is easily reproducible by registering the IDocumentHashProvider in the function startup: builder.Services.AddSingleton<IDocumentHashProvider>((sp) => new MD5DocumentHashProvider()); and then fetch the dependency in function method. It doesn't matter if you do it with ctor injection, over the contextAccessor, or with the HTTPContext in the Request, it all fails : var services = req.HttpContext.RequestServices;
var test = services .GetService<ReviewRepository>(); // works
var test = services .GetService<IDocumentHashProvider>(); // 💣 And now it becomes really weird.
|
so |
it looks like that. GetService stops the execution of the function when it doesn't find something and doesn't just return null. though it's not the implementation of the DI as it's the same Microsoft.Extension.DependencyInjection package which handles this. |
though it's probably just because of using the wrong ctor for the HashProvider |
hm.. it's not supposed to be created by the DI. The DI should just resolve it :D |
looks like manually registering the HashDocumentProvider after the GraphQL-initialization fixed the issue. OneCyrus/GraphQL-AzureFunctions-HotChocolate@a37c68a#diff-fbd03c53f6f1dc7701583e41f0cda5c8 the feat_nativeDI branch works now with the latest HC version: |
Thank you. I have been able to get it working using the suggested approach for now. Keep me posted if it gets fixed in V 11. Thanks |
@michaelstaib do fix this here: https://github.com/ChilliCream/hotchocolate/blob/cf600304845e716fb9dfacdce491bc59c31bf1b8/src/Core/Core/Execution/Extensions/QueryExecutionBuilderExtensions.cs#L706 or do we want to remove the unused empty constructor? |
This one is now merged and will be part of 10.3.4 |
Describe the bug
Null Exception during Dependency Injection within Azure Functions. Working in 10.0.1 only.
To Reproduce
Using Repository located https://github.com/OneCyrus/GraphQL-AzureFunctions-HotChocolate
Steps to reproduce the behavior:
eg
Expected behavior
I am not sure what fundamental changes occur in between 10.0.1 and 10.2.0, but something is affecting the DI stopping it from working in Azure Functions.
Desktop (please complete the following information):
Additional context
Here are some of the variables I see when the exception is encountered.
My guess is there is a change in what this bit of code does which is causing the DI issues
Any pointers or assistance would be greatly apreciated
Thanks, Basil
The text was updated successfully, but these errors were encountered: