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
wtgodbe added a commit that referenced this pull request Sep 3, 2025
* Merge pull request #63458 from dotnet/darc-release/10.0-0b5f1d61-512f-46bf-9db1-6245ce11f284

[release/10.0] Source code updates from dotnet/dotnet

* Add unsupported compat switch for property injection (#63493)

* [release/10.0] Remove duplicate RedirectManager injection in Blazor Web App ChangePassword template (#63452)

* Initial plan

* Fix duplicate RedirectManager injection in ChangePassword.razor template

Co-authored-by: ilonatommy <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: ilonatommy <[email protected]>

* Update .NET SDK version in global.json

---------

Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Javier Calvarro Nelson <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: ilonatommy <[email protected]>
Co-authored-by: William Godbe <[email protected]>
@danroth27
Copy link
Member

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.

@javiercn Please open an issue for adding the public API so we don't lose track of it.

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.

4 participants