Skip to content

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Sep 1, 2025

Add switch to disable property injection in default component factory

Adds an unsupported app context switch to disable property injection within the default component factory. The switch prevents injection of @inject properties so a custom activator can handle activation and property population.

Description

Adds a new, unsupported AppContext switch that disables property injection for components activated through the default component factory. When enabled, the framework will skip injecting @inject properties so that a custom activator (for example, one backed by a different DI container) can perform property activation instead.

This change addresses the scenario where component property activation currently always uses the app's DI container and cannot be overridden by custom activators. With the switch, custom implementations that rely on a separate container can take full control of property activation.

Customer Impact

This is not a switch for public consumption but rather a switch we are providing to support first parties in 10.0. On 11.0 we will add a public API to support this scenario and remove this switch.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Justification: The change is gated behind an unsupported AppContext switch and is opt-in. It does not change the default behavior and only affects activation when the switch is explicitly enabled.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an unsupported AppContext switch to disable property injection in Blazor's default component factory. The feature allows custom component activators to take full control of property injection by bypassing the framework's built-in @inject property handling.

Key changes:

  • Introduces Microsoft.AspNetCore.Components.Unsupported.DisablePropertyInjection AppContext switch
  • Conditionally skips property injection in InstantiateComponent method when switch is enabled
  • Maintains backward compatibility with opt-in behavior

@lewing lewing merged commit 76335f6 into release/10.0 Sep 2, 2025
28 checks passed
@lewing lewing deleted the javiercn/disable-property-injection-via-app-context-switch branch September 2, 2025 17:31
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc2 milestone Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants