Skip to content

Commit 88192a5

Browse files
authored
HostBuilder validation enabled (#42042)
1 parent 218916a commit 88192a5

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

docs/core/compatibility/9.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you're migrating an app to .NET 9, the breaking changes listed here might aff
2020
| Title | Type of change | Introduced version |
2121
|------------------------------------------------------------------------------------------|---------------------|--------------------|
2222
| [DefaultKeyResolution.ShouldGenerateNewKey has altered meaning](aspnet-core/9.0/key-resolution.md) | Behavioral change | Preview 3 |
23+
| [HostBuilder enables ValidateOnBuild/ValidateScopes in development environment](aspnet-core/9.0/hostbuilder-validation.md) | Behavioral change | Preview 7 |
2324

2425
## Core .NET libraries
2526

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: "Breaking change: HostBuilder enables ValidateOnBuild/ValidateScopes in development environment"
3+
description: Learn about the breaking change in .NET 9 where HostBuilder now enables ValidateOnBuild and ValidateScopes in the development environment.
4+
ms.date: 08/05/2024
5+
---
6+
# HostBuilder enables ValidateOnBuild/ValidateScopes in development environment
7+
8+
Previously, no validation was enabled by default. Now, in the [development environment](/aspnet/core/fundamentals/environments), <xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateOnBuild> and <xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateScopes> are enabled.
9+
10+
## Version introduced
11+
12+
.NET 9 Preview 7
13+
14+
## Previous behavior
15+
16+
<xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateOnBuild> and <xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateScopes> defaulted to `false` and were only enabled when they were explicitly set by calling <xref:Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseDefaultServiceProvider%2A>.
17+
18+
## New behavior
19+
20+
In the [development environment](/aspnet/core/fundamentals/environments) when options haven't been set with <xref:Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseDefaultServiceProvider%2A>, <xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateOnBuild> and <xref:Microsoft.Extensions.DependencyInjection.ServiceProviderOptions.ValidateScopes> are set to `true`.
21+
22+
## Type of breaking change
23+
24+
This change is a [behavioral change](../../categories.md#behavioral-change).
25+
26+
## Reason for change
27+
28+
Validation helps to catch problems early in application startup rather than later (or not at all) when the application interacts with its service provider.
29+
30+
## Recommended action
31+
32+
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 <xref:Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseDefaultServiceProvider%2A>.
33+
34+
## Affected APIs
35+
36+
- <xref:Microsoft.Extensions.Hosting.HostBuilder>
37+
- <xref:Microsoft.Extensions.Hosting.HostBuilder.Build>

docs/core/compatibility/toc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ items:
1212
items:
1313
- name: DefaultKeyResolution.ShouldGenerateNewKey has altered meaning
1414
href: aspnet-core/9.0/key-resolution.md
15+
- name: HostBuilder enables ValidateOnBuild/ValidateScopes in development environment
16+
href: aspnet-core/9.0/hostbuilder-validation.md
1517
- name: Core .NET libraries
1618
items:
1719
- name: Adding a ZipArchiveEntry sets header general-purpose bit flags
@@ -958,6 +960,8 @@ items:
958960
items:
959961
- name: DefaultKeyResolution.ShouldGenerateNewKey has altered meaning
960962
href: aspnet-core/9.0/key-resolution.md
963+
- name: HostBuilder enables ValidateOnBuild/ValidateScopes in development environment
964+
href: aspnet-core/9.0/hostbuilder-validation.md
961965
- name: .NET 8
962966
items:
963967
- name: ConcurrencyLimiterMiddleware is obsolete

0 commit comments

Comments
 (0)