-
Notifications
You must be signed in to change notification settings - Fork 227
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
Fix S6966 FP: EntityFrameworks IDbContextFactory CreateDbContext method is preferred over its Async counterpart #9590
Comments
Hello @manuel-rw, I am not able to reproduce the issue with your code snippet. Am I missing something? |
Hi @sebastien-marichal , As far as I understood the linked issues, this should not emit S6966 because the async method is intended for special usecases only and causes additional overhead. Hence Sonar should not suggest the async method. |
That's not my understanding. The only overhead I see is people relying on the covariance, which is not a problem in your case (I might miss some context). Why do you think it is only intended for special use cases? For me, the rule makes sense in this context. |
Hi, Referencing dotnet/efcore#26630 again:
And as mentioned by https://stackoverflow.com/a/71186090, the method does not perform any I/O or actions that would require asynchronous handling. |
Thank you for bringing up the Roslyn PR; I was missing it. I agree now that |
Description
Rule ID: S6966
As documented in dotnet/efcore#26630, the CreateDbContextAsync() is a method for special edge cases only.
The synchronous CreateDbContext() is preferred for most cases. This has been reflected in updated rules in the Roslyn analyzers: dotnet/roslyn-analyzers#7036
However, Sonar currently emits S6966 for any usage of the
CreateDbContext()
method.Repro steps
Expected behavior
Since
CreateDbContext
is preferred Sonar should not emit a diagnostic warning.Actual behavior
Sonar emits the S6966 warning and proposes the
CreateDbContextAsync
method instead.Known workarounds
CreateDbContext()
and ignores the warning on this specific line. Obvious disadvantage being that the efcore API is being hidden and additional complexity is being introduced.Related information
9.27 (build 93347)
, VB9.27 (build 93347)
The text was updated successfully, but these errors were encountered: