Add support for constructor injection in components#28
Merged
LittleLittleCloud merged 4 commits intoRazorConsole:mainfrom Oct 15, 2025
Merged
Add support for constructor injection in components#28LittleLittleCloud merged 4 commits intoRazorConsole:mainfrom
LittleLittleCloud merged 4 commits intoRazorConsole:mainfrom
Conversation
LittleLittleCloud
approved these changes
Oct 15, 2025
Member
|
LGTM, approved with minor feedback |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds constructor injection support for Razor components by implementing a custom IComponentActivator that uses ActivatorUtilities instead of Activator.CreateInstance. This enables developers to inject dependencies through constructors rather than relying solely on property injection with [Inject] attributes.
Key Changes
- Introduced
ComponentActivatorclass that leveragesActivatorUtilitiesfor service-aware component instantiation - Registered
ComponentActivatoras a singleton service in the DI container - Added comprehensive test coverage including keyed services, error scenarios, and basic constructor injection
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/RazorConsole.Core/Utilities/ComponentActivator.cs | New activator implementation supporting constructor injection via ActivatorUtilities |
| src/RazorConsole.Core/AppHost.cs | Registers ComponentActivator in DI container and removes unused imports |
| src/RazorConsole.Tests/ComponentActivatorTests.cs | Comprehensive test suite verifying constructor injection, keyed services, and error handling |
LittleLittleCloud
approved these changes
Oct 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25
This pull request introduces support for constructor injection for Razor Components by implementing a custom IComponentActivator. This change allows developers to use constructor injection for their dependencies, which is a more modern and robust pattern compared to relying solely on property injection with [Inject].
Description of Changes
As discussed in issue #25, the default IComponentActivator uses Activator.CreateInstance(type), which is limited to parameterless constructors. This prevents constructor injection.
This PR addresses this by: