Consolidate duplicate service registration between AppHost and RazorConsoleRenderer#187
Merged
LittleLittleCloud merged 2 commits intomainfrom Nov 25, 2025
Merged
Conversation
…leServices extension method Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Consolidate AppHost and RazorConsoleRenderer to eliminate duplicate code
Consolidate duplicate service registration between AppHost and RazorConsoleRenderer
Nov 25, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR successfully consolidates duplicate service registration code from AppHost.cs and RazorConsoleRenderer.cs into a single, reusable extension method. The refactoring improves maintainability by eliminating ~35 lines of duplicated code in each location.
Key changes:
- Introduces a new public API (
AddRazorConsoleServices()) that consolidates all core Razor Console service registrations - Simplifies both
AppHost.RegisterDefaults<T>()andRazorConsoleRenderer.InitializeAsync()to delegate to the shared method - Makes the service registration pattern available for external consumers who want to manually configure DI without using the host builder extensions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/RazorConsole.Core/RazorConsoleServiceCollectionExtensions.cs |
New file containing the consolidated AddRazorConsoleServices() extension method with all core service registrations (renderer, focus management, keyboard handling, syntax highlighting, VDOM translation) |
src/RazorConsole.Core/AppHost.cs |
Simplified RegisterDefaults<T>() to call shared extension method; removed duplicate registration code and unnecessary imports |
src/RazorConsole.Website/RazorConsoleRenderer.cs |
Simplified InitializeAsync() to call shared extension method; removed duplicate registration code and unnecessary imports |
TeseySTD
approved these changes
Nov 25, 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.
AppHost.csandRazorConsoleRenderer.cscontained nearly identical service registration code (~35 lines each). This PR extracts the common registrations into a shared extension method.Changes
RazorConsoleServiceCollectionExtensions.cs- PublicAddRazorConsoleServices()extension method containing all core service registrations (renderer, focus management, keyboard handling, syntax highlighting, VDOM translators)AppHost.RegisterDefaults<T>()- Now delegates to shared methodRazorConsoleRenderer.InitializeAsync()- Now delegates to shared methodUsage
The new method is public, enabling external consumers to set up the Razor Console DI container without using the host builder extensions.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.