HostBuilder enables ValidateOnBuild/ValidateScopes in development environment

Previously, no validation was enabled by default. Now, in the development environment, ValidateOnBuild and ValidateScopes are enabled.

Version introduced

.NET 9 Preview 7

Previous behavior

ValidateOnBuild and ValidateScopes defaulted to false and were only enabled when they were explicitly set by calling UseDefaultServiceProvider.

New behavior

In the development environment when options haven't been set with UseDefaultServiceProvider, ValidateOnBuild and ValidateScopes are set to true.

Type of breaking change

This change is a behavioral change.

Reason for change

Validation helps to catch problems early in application startup rather than later (or not at all) when the application interacts with its service provider.

No action necessary if your application validates successfully. If you do see a validation error when testing in development, first try to fix it. If you can't fix it, you can disable validation by calling UseDefaultServiceProvider.

Affected APIs