-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Blazor] Introduce IComponentPropertyActivator for property injection #64595
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
base: main
Are you sure you want to change the base?
Conversation
This PR introduces a new public abstraction IComponentPropertyActivator for Blazor property injection, addressing #63451. - Add IComponentPropertyActivator interface for customizing property injection - Add DefaultComponentPropertyActivator internal implementation - Refactor ComponentFactory to use the new abstraction - Update Renderer to resolve IComponentPropertyActivator from DI - Add comprehensive unit tests for the new functionality
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.
Pull request overview
This PR introduces a new public extensibility point IComponentPropertyActivator that allows customization of property injection in Blazor components, addressing the gap identified in issue #63451. The change follows the same design pattern as IComponentActivator and enables scenarios like custom DI containers and advanced property injection requirements in Blazor Hybrid applications.
Key Changes:
- New public interface
IComponentPropertyActivatorwith proper XML documentation and trimming annotations - Internal
DefaultComponentPropertyActivatorimplementation extracted fromComponentFactorywith caching and Hot Reload support - Refactored
ComponentFactoryto delegate property injection to the activator, simplifying the class and improving separation of concerns
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Components/Components/src/IComponentPropertyActivator.cs |
New public interface defining the property activation contract with comprehensive documentation |
src/Components/Components/src/DefaultComponentPropertyActivator.cs |
Default implementation with caching, Hot Reload integration, and keyed service support |
src/Components/Components/src/ComponentFactory.cs |
Refactored to use IComponentPropertyActivator, removing embedded property injection logic and simplifying the class |
src/Components/Components/src/RenderTree/Renderer.cs |
Added DI resolution for IComponentPropertyActivator with fallback to default, integrated cache clearing for Hot Reload |
src/Components/Components/src/PublicAPI.Unshipped.txt |
Added new public API surface entries |
src/Components/Components/test/ComponentFactoryTest.cs |
Updated existing tests with new constructor parameter, added comprehensive tests for custom property activator scenarios |
src/Components/Components/test/RouteViewTest.cs |
Updated test to pass new required IComponentPropertyActivator parameter |
src/Components/Authorization/test/AuthorizeRouteViewTest.cs |
Updated test to pass new required IComponentPropertyActivator parameter |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
ilonatommy
left a comment
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.
Looks good to me but I would prefer more reviewers to see it.
Fine with me. Just to set the context. This follows the same pattern as everything else on the framework (MVC/RazorPages/Controllers). The PR is mostly defining the equivalent abstraction for components and moving the code that was on the DefaultComponentFactory into the activator. |
Summary
This PR introduces a new public abstraction
IComponentPropertyActivatorfor customizing property injection in Blazor components, addressing the extensibility gap identified in #63451.Background
Currently, Blazor's property injection logic (for
[Inject]attributes) is embedded within the internalComponentFactoryclass with no way to customize it. WhileIComponentActivatorexists for customizing component instantiation, there's no equivalent for property injection.This becomes problematic for scenarios like:
Changes
New Public API
Implementation Details
IComponentPropertyActivator: New public interface following the same pattern as MVC's property activatorsDefaultComponentPropertyActivator: Internal default implementation that:ConcurrentDictionary[Inject(Key = "...")]ComponentFactory: Refactored to acceptIComponentPropertyActivatoras a dependencyRenderer: Updated to resolveIComponentPropertyActivatorfrom DI with fallback to defaultTests
Added comprehensive unit tests covering:
API Usage
Related Issues