Skip to content

Add externally accessible lifecycle events for silos #9771

@ReubenBond

Description

@ReubenBond

We recently deprecated IStartupTask and we have included a warning about its perils in the docs for quite some time now. However, because IHost can choose to start/stop IHostedService instances in any order it is difficult to be sure that the silo is in a certain state (eg, ready to receive requests) by the time IHostedService.StartAsync is called. Similarly, it's difficult to know when a silo begins shutting down and when it has completed shutting down.

To remedy this, we should offer an interface similar to IHostApplicationLifetime which can be used to hook into certain lifecycle stages externally.

One open question is whether we should expose these events using a Task or a CancellationToken. For startup, it's more convenient to wait on a Task than a CancellationToken. Additionally, callbacks on CancellationToken cannot themselves be asynchronous. Ideally, we would have something which is both awaitable and where consumers can optionally register an asynchronous method to prevent the silo from advancing (eg, continuing to shutdown) until the callback has completed - with support for Task-returning callbacks.

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