Use BackgroundService and resolve with HostApplicationBuilder#23
Use BackgroundService and resolve with HostApplicationBuilder#23LittleLittleCloud merged 6 commits intoRazorConsole:mainfrom
Conversation
…tates using other hosted BackgroundService(s) to update the UI
|
Please create a issue for this pull request for tracking, and highlight the advantages of the switch. Some notable ones may be the dependency on IHost and it's application builder means we can leverage existing integrations on those interfaces. It would also allow us to leverage the IConfigurationManager interface and allow users to bind Iconfiguration to IOptions configurations for their application. |
|
@DericHuynh It's the official host application builder. I think it's best implementing I would also keep the current implementation and apply it in a different type to support backward. Maybe add a obsolete notice |
|
I completely understand that IHost is everywhere. Which is why I created arguments for the switch. However, it is best practice to create issues for discussion and requirements gathering, then resolving issues through PRs. |
For sure, otherwise its a breaking change and we'd need to discuss a major version update, following semantic versioning. For example 0.0.5 -> 1.0.0 |
|
I didn't see a contribution guide for this repo, hence just creating the PR. Did I miss one? I will create an issue and link it if required. In my opinion, given the early stages of this project, I feel it overly bureaucratic. The project is not even 1.x old. Related, Semantic Versioning does not require a major bump for breaking changes while at 0.x, thus I did not make any significant effort to maintain backwards compatibility. Knowingly and willingly adding deprecated/obsolete methods while at 0.x seems illogical to me, 0.x is when the API surface is being designed, consumers should expect breaking changes. |
# Conflicts: # src/RazorConsole.Core/AppHost.cs
Would be appreciated if you can create a tracking issue given that it's not a small change. I can also create one for you. Will update the contribution guide with the preference of creating issue first before submitting large PR.
I am open to breaking change for now given the early stage of this project. For this PR you can bump minor version to indicate the refactor change in host builder since we might want to make a release after this PR merged |
|
I have created the issue #40 and bumped the minor version. Unrelated, but may I gently suggest using GitVersion |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the RazorConsole architecture to use Microsoft's BackgroundService and HostApplicationBuilder instead of the custom ConsoleApp<TComponent> class, enabling better dependency injection integration and reducing boilerplate code.
Key changes:
- Replaced custom
ConsoleApp<TComponent>withComponentService<TComponent>that inherits fromBackgroundService - Modified
AppHostto useHostApplicationBuilderand returnIHostinstances - Updated service registration pattern from configuration callbacks to direct DI container usage
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/RazorConsole.Core/AppHost.cs | Major refactor replacing ConsoleApp with BackgroundService-based architecture and HostApplicationBuilder |
| src/RazorConsole.Core/RazorConsole.Core.csproj | Added Microsoft.Extensions.Hosting package dependency |
| src/RazorConsole.Tests/ConsoleAppTests.cs | Updated test to use new DI service registration pattern |
| src/RazorConsole.Gallery/Program.cs | Updated to use new builder.Services API instead of ConfigureServices |
| examples/LLMAgentTUI/Program.cs | Updated to use new builder.Services API instead of ConfigureServices |
| nuget/nuget-package.props | Version bump from 0.0.6 to 0.1.0 |
Comments suppressed due to low confidence (1)
src/RazorConsole.Core/AppHost.cs:1
- The indentation uses a tab character instead of spaces. According to the .editorconfig rule mentioned in the coding guidelines, four-space indentation should be used consistently.
using Microsoft.AspNetCore.Components;
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
|
Thanks @flynny75 approved and merged
It's my first time hearing GitVersion, let me take a look and rethink about it |
Implement in BackgroundService and use Microsoft HostApplicationBuilder to facilitate other DI usages
Eg. using a UI binder object with events, binding to the events in the razor, and raising the events in other BackgroundService(s)
Can remove a lot of boilerplate and rely on IHost