Expose IVdomElementTranslator and replace MEF with Service Provider for custom translators#36
Merged
LittleLittleCloud merged 9 commits intomainfrom Oct 16, 2025
Conversation
- Made IVdomElementTranslator and TranslationContext public - Made VdomSpectreTranslator public with public constructor - Exposed utility methods as public static methods - Made IAnimatedConsoleRenderable public - Removed MEF (System.Composition) dependency entirely - Created VdomTranslatorServiceCollectionExtensions for registering translators with priority - Updated AppHost to register default translators via DI - Updated ConsoleRenderer to accept VdomSpectreTranslator from DI - Updated all translator files to remove [Export] attributes - Updated all Razor components to remove System.Composition using - Created TestHelpers for test renderer creation - Added CustomTranslatorTests to validate custom translator registration - All 63 tests pass successfully Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Expose IVdomElementTranslator for external use
Expose IVdomElementTranslator and replace MEF with Service Provider for custom translators
Oct 16, 2025
LittleLittleCloud
requested changes
Oct 16, 2025
Member
LittleLittleCloud
left a comment
There was a problem hiding this comment.
@copilot fix comments
src/RazorConsole.Core/Vdom/VdomTranslatorServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
- Moved IVdomElementTranslator to its own file with Priority property - Moved TranslationContext to its own file (no longer nested) - Converted all translator classes from nested to standalone classes - Each translator now implements Priority property directly - Removed PrioritizedTranslator wrapper class - Removed IPrioritizedTranslator interface - Updated registration to use Priority property from interface - Updated all tests and helper methods - All 63 tests pass successfully Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Member
|
@copilot |
- Created custom-translators.md with detailed guide - Covers architecture, built-in translators, and extensibility - Includes examples for creating custom translators - Documents utility methods and best practices - Provides troubleshooting and testing guidance Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Contributor
Author
Done. Created comprehensive design document at
See commit 94a6d85. |
… method for improved maintainability and ordering
…b.com/LittleLittleCloud/RazorConsole into copilot/expose-ivdomelementtranslator
Member
|
@copilot Update readme with a section on how to register custom translators and link to the design doc |
- Added comprehensive Custom Translators section after Built-in Components - Includes example of creating a custom translator (OverflowElementTranslator) - Shows registration pattern using AddVdomTranslator - Demonstrates usage in Razor components - Links to detailed design doc for advanced scenarios Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Contributor
Author
Done. Added comprehensive Custom Translators section to README.md with:
See commit 294a293. |
…b.com/LittleLittleCloud/RazorConsole into copilot/expose-ivdomelementtranslator
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.
Overview
This PR addresses #35 by exposing the
IVdomElementTranslatorinterface and related APIs, enabling users to create custom VDOM element translators. It also replaces the MEF (Managed Extensibility Framework) dependency with the standard Microsoft.Extensions.DependencyInjection service provider for a cleaner, more maintainable architecture.Motivation
Previously, all VDOM translators were internal and used MEF for discovery, making it impossible for users to extend RazorConsole with custom Spectre.Console renderables. This prevented users from implementing features like overflow handling or other custom components that aren't built into the framework.
Changes
Public APIs
The following APIs are now public and documented:
VdomSpectreTranslator- Main translator class with public constructorIVdomElementTranslator- Standalone interface for implementing custom translators with built-inPrioritypropertyTranslationContext- Standalone context class for recursive translation of child nodesIAnimatedConsoleRenderable- Interface for animated renderablesArchitecture Improvements
VdomSpectreTranslatorIVdomElementTranslatorincludes aPriorityproperty, eliminating the need for wrapper classesService Provider Integration
Replaced MEF with Microsoft.Extensions.DependencyInjection:
System.Compositionpackage dependency[Export]attributes from translator classesVdomTranslatorServiceCollectionExtensionswith fluent registration APIAppHostto register default translators via DIConsoleRendererto receiveVdomSpectreTranslatorfrom DI containerPriority-Based Registration
Users can now register custom translators using the standard DI pattern:
Built-in translators use priorities from 10-1000, allowing users to insert custom translators before, between, or after default handlers by implementing the appropriate Priority value.
Example Usage
Creating a custom translator for overflow handling:
Then use it in a Razor component:
Documentation
Added comprehensive documentation for custom translators:
Design Documentation
Created
design-doc/custom-translators.mdwith detailed coverage of:README Updates
Added Custom Translators section to
README.mdincluding:AddVdomTranslatorTesting
CustomTranslatorTestswith 3 new tests validating custom translator registration and priority handlingTestHelpersutility for consistent test renderer setupBreaking Changes
None for users of the public API. The internal MEF-based system has been replaced, but since
IVdomElementTranslatorwas previously internal, no external code should be affected.Migration Guide
For any internal/custom translators that were using the internal MEF approach:
Before:
After:
Benefits
Closes #35
Original prompt
Fixes #35
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.