Skip to content

Implement ComponentService via BackgroundService #40

@flynny75

Description

@flynny75

The current implementation of ConsoleAppBuilder lacks functionality compared to Microsoft.Extensions.Hosting.Host.CreateApplicationBulider. It does not support BackgroundService, and it reimplements much of the console exit key handling.

The main driver for this issue was the inability to impact the UI via a binder object injected into both a BackgroundService and a Razor component. The HostApplicationBuilder created by CreateApplicationBuilder already has support for BackgroundService, and takes care of console exit codes and service lifecycle events. The ComponentService is trivial to reimplement into a BackgroundService where it can receive service lifecycle events.

This change has been implemented in #23

Things to note in the PR is the requirement to remove the logging providers - there does not appear to be a simple way to remove the console provider (callers are expected to add their own logging providers via the HostApplicationBuilder configuration callback), and the override of the StopAsync method (the Task created by the Host is discarded and not awaited. The default behaviour of the Host is to exit when any of its BackgroundService(s) throw, and invoke the StopAsync method of all BackgroundService(s), including the faulted, where the original exception can be thrown and then rethrown by the Host. This quirk may change in future versions of the Hosting package)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions