Skip to content

Consolidate duplicate service registration between AppHost and RazorConsoleRenderer#187

Merged
LittleLittleCloud merged 2 commits intomainfrom
copilot/consolidate-apphost-razorconsole
Nov 25, 2025
Merged

Consolidate duplicate service registration between AppHost and RazorConsoleRenderer#187
LittleLittleCloud merged 2 commits intomainfrom
copilot/consolidate-apphost-razorconsole

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

AppHost.cs and RazorConsoleRenderer.cs contained nearly identical service registration code (~35 lines each). This PR extracts the common registrations into a shared extension method.

Changes

  • New RazorConsoleServiceCollectionExtensions.cs - Public AddRazorConsoleServices() extension method containing all core service registrations (renderer, focus management, keyboard handling, syntax highlighting, VDOM translators)
  • Simplified AppHost.RegisterDefaults<T>() - Now delegates to shared method
  • Simplified RazorConsoleRenderer.InitializeAsync() - Now delegates to shared method

Usage

var services = new ServiceCollection();
services.Configure<ConsoleAppOptions>(_ => { });
services.AddRazorConsoleServices();  // All core services registered

The new method is public, enabling external consumers to set up the Razor Console DI container without using the host builder extensions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Consolidated the AppHost and RazorConsoleRenderer</issue_title>
<issue_description>There are a lot of duplicate code among those classes</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

…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
@LittleLittleCloud LittleLittleCloud marked this pull request as ready for review November 25, 2025 07:22
Copilot AI review requested due to automatic review settings November 25, 2025 07:22
Copy link
Contributor

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 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>() and RazorConsoleRenderer.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

@LittleLittleCloud LittleLittleCloud merged commit 38bfd6f into main Nov 25, 2025
16 checks passed
@LittleLittleCloud LittleLittleCloud deleted the copilot/consolidate-apphost-razorconsole branch November 25, 2025 16:41
@github-actions github-actions bot added this to the v0.2.0 milestone Nov 25, 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.

Consolidated the AppHost and RazorConsoleRenderer<T>

4 participants