Allow IOptions for ConsoleAppOptions for configuration#49
Merged
LittleLittleCloud merged 11 commits intoRazorConsole:mainfrom Oct 23, 2025
Merged
Allow IOptions for ConsoleAppOptions for configuration#49LittleLittleCloud merged 11 commits intoRazorConsole:mainfrom
LittleLittleCloud merged 11 commits intoRazorConsole:mainfrom
Conversation
- Change HostApplicationBuilder to IHostApplicationBuilder for more flexibility - Separate CreateApplicationBuilder from UseRazorConsole for cleaner code style - Update tests to follow non-fluent pattern
Use IHostApplicationBuilder interface and improve code style
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enables the ConsoleAppOptions class to be configured using the standard IOptions<T> pattern while maintaining backward compatibility by avoiding direct IOptions<> dependencies in consuming components. The change allows developers to use services.Configure<ConsoleAppOptions>() instead of manually registering singleton instances.
Key changes:
- Modified
ConsoleAppOptionsregistration to resolve fromIOptions<ConsoleAppOptions>internally while exposing a plain POCO to consumers - Updated test to use
Configure<ConsoleAppOptions>()instead ofAddSingleton<ConsoleAppOptions>() - Added new test verifying default options resolution through the DI container
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/RazorConsole.Tests/ConsoleAppTests.cs | Refactored existing test to use Configure<ConsoleAppOptions>() and added new test for default options resolution |
| src/RazorConsole.Core/AppHost.cs | Changed registration to resolve ConsoleAppOptions from IOptions<ConsoleAppOptions> using a factory |
| examples/LLMAgentTUI/Program.cs | Updated example to use Configure<ConsoleAppOptions>() pattern instead of manual singleton registration |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
LittleLittleCloud
approved these changes
Oct 23, 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 #46
Enables use of IOption pattern configuration while still avoiding IOptions<> dependency through POCO class registration.
Added test for IOption resolution since it depends on the generic host itself injecting the IOptions dependencies.