-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Don't enable validation when UseDefaultServiceProvider is called #105170
Don't enable validation when UseDefaultServiceProvider is called #105170
Conversation
@ericstj It seems to me that this would correct the problem of Reverting my change would mean scope and dependency-chain validation would not happen by default in development where |
@wcsanders1 was this what you had in mind when you added |
This is what I had in mind. I neglected to set it to false because I failed to see that the factory method also uses that constructor. |
@steveharter could you review this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct in assuming that without this fix UseServiceProviderFactory
is completely broken in development? If so, I wonder if we should backport to preview7.
Not entirely sure this is the right thing, or if we should just revert the regressing change.
This is better than what we had but reading the following from #97091 makes me tempted to revert this.
It looks like this failure to validate the scope is a result of calling the
HostBuilder
constructor rather than theCreateDefaultBuilder
method, which enables scope validation when the environment isDevelopment
:
I think this analysis is correct, but I don't think we should make the HostBuilder constructor behave like CreateDefaultBuilder just because we like the CreateDefaultBuilder behavior better. CreateDefaultBuilder is meant to be more opinionated.
The only reason GrandNode happened to be calling the following
.UseDefaultServiceProvider((context, options) =>
{
options.ValidateScopes = false;
options.ValidateOnBuild = false;
});
was because it was using CreateDefaultBuilder instead of the HostBuilder constructor. I think there will be far more code that was previously using HostBuilder that won't explicitly disable validation because it wasn't necessary. While resolving a scoped service from the root container is generally a bad idea and can probably always be avoided with proper care, there's plenty of scenarios where it won't cause real problems.
Yes, my plan is to take this as ask for P7.
Yes, that's why I put the breaking-change label on the original PR. I thought the goal of that PR was to intentionally enable this in and document that as a breaking change. Do folks think it's too breaking for the value that it provides? We could let this go out this way in P7 (bringing this fix in) and see what folks say and revert completely it if it's too breaking. |
Yes we need this fix since |
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
Show resolved
Hide resolved
…tBuilderTests.cs Co-authored-by: Steve Harter <steveharter@users.noreply.github.com>
/backport to release/9.0-preview7 |
Started backporting to release/9.0-preview7: https://github.com/dotnet/runtime/actions/runs/10066731186 |
Fix #105134
Not entirely sure this is the right thing, or if we should just revert the regressing change.
Please have a look @wcsanders1