Skip to content

Add IServiceLifecycle interface with lifecycle hooks for client and silo#9792

Merged
ReubenBond merged 19 commits into
dotnet:mainfrom
ledjon-behluli:silo-lifecycle-events
Feb 16, 2026
Merged

Add IServiceLifecycle interface with lifecycle hooks for client and silo#9792
ReubenBond merged 19 commits into
dotnet:mainfrom
ledjon-behluli:silo-lifecycle-events

Conversation

@ledjon-behluli

@ledjon-behluli ledjon-behluli commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

close #9771

Microsoft Reviewers: Open in CodeFlow

Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
@ledjon-behluli

ledjon-behluli commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

@ReubenBond addressed the comments, PTAL!

WDYT about this, I am unsure, but lean more towards (a)waiting indefinitely

image

@ReubenBond

Copy link
Copy Markdown
Member

@ledjon-behluli I think relying on them respecting the CT is ok (even if not defensive)

Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
Comment thread src/Orleans.Runtime/Lifecycle/SiloLifetime.cs Outdated
@ledjon-behluli ledjon-behluli marked this pull request as ready for review November 30, 2025 15:15
@ledjon-behluli

ledjon-behluli commented Nov 30, 2025

Copy link
Copy Markdown
Contributor Author

@ReubenBond Added proper tests & removed the toy/test console app. We should consider not having the TerminateOnError and control it within the component i.e. Starting events should terminate, and while stopping we log and swallow, but other than that this is now ready AFAIC.

P.s: I do not have a strong opinion on the matter of TerminateOnError being an internal thing, or left to the user.

@shacal

shacal commented Dec 1, 2025

Copy link
Copy Markdown

Yes please!

@ledjon-behluli ledjon-behluli changed the title Silo Lifecycle Events Service Lifetime Events Dec 14, 2025
@ReubenBond ReubenBond requested a review from Copilot December 14, 2025 22:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new service lifetime event system for Orleans, providing a cleaner API for observing and participating in client/silo lifecycle stages. The implementation adds IServiceLifetime with three stages (Started, Stopping, Stopped) that allow callbacks to be registered and executed at specific points in the service lifecycle.

Key changes:

  • New IServiceLifetime and IServiceLifetimeStage interfaces providing callback registration and cancellation token support
  • ServiceLifetimeStage implementation handling callback execution, error handling, and late registrations
  • Registration in both client and silo service containers with comprehensive test coverage

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Orleans.Core/Lifecycle/ServiceLifetimeStage.cs Core implementation of lifecycle stages with callback management, error handling, and thread-safe registration
src/Orleans.Core/Lifecycle/ServiceLifetime.cs Main service lifetime coordinator that wires up Started, Stopping, and Stopped stages to the underlying lifecycle observable
src/Orleans.Runtime/Hosting/DefaultSiloServices.cs Registers ServiceLifetime for silo lifecycle with dependency injection (also reorganizes using statements alphabetically)
src/Orleans.Core/Core/DefaultClientServices.cs Registers ServiceLifetime for client lifecycle with dependency injection
test/NonSilo.Tests/ServiceLifetimeTests.cs Comprehensive test suite covering callback execution, cancellation, error handling, late registration, and concurrency scenarios

Comment thread src/Orleans.Core/Lifecycle/ServiceLifetimeStage.cs Outdated
Comment thread test/NonSilo.Tests/ServiceLifetimeTests.cs Outdated
Comment thread test/NonSilo.Tests/ServiceLifetimeTests.cs Outdated
Comment thread src/Orleans.Core/Lifecycle/ServiceLifetimeStage.cs Outdated
Comment thread test/NonSilo.Tests/ServiceLifetimeTests.cs Outdated
Comment thread src/Orleans.Core/Lifecycle/ServiceLifetimeStage.cs Outdated
@ReubenBond ReubenBond force-pushed the silo-lifecycle-events branch from a68a22a to 3fcc96a Compare February 15, 2026 22:26
@ReubenBond

Copy link
Copy Markdown
Member

@ledjon-behluli let's use the term 'lifecycle' instead of 'lifetime' here, since lifetime usually refers to the span of time for which something is alive whereas we are interested in the various stages/events as well. I'll make the change and push and update

@ReubenBond ReubenBond changed the title Service Lifetime Events Add IServiceLifecycle interface with lifecycle hooks for client and silo Feb 15, 2026
ReubenBond added a commit to ledjon-behluli/orleans that referenced this pull request Feb 15, 2026
Use lifecycle terminology across PR dotnet#9792 types, registrations, files, and tests while preserving behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ledjon-behluli and others added 9 commits February 15, 2026 15:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Prevent duplicate NotifyCompleted calls from re-executing callbacks by awaiting the existing completion task.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use lifecycle terminology across PR dotnet#9792 types, registrations, files, and tests while preserving behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@ReubenBond ReubenBond added this pull request to the merge queue Feb 16, 2026
Merged via the queue into dotnet:main with commit 693590a Feb 16, 2026
65 checks passed
rkargMsft pushed a commit to rkargMsft/orleans that referenced this pull request Feb 27, 2026
… silo (dotnet#9792)

* Initial cut for silo lifecycle events

* fix print statement

* xml doc typo

* strengthen the threading gurantees for callback execs

* xml docs and cancellation sematics

* wording

* addressed comments

* addressed comments

* add tests

* remove test console app

* unify silo and client lifetime handling + renamed to ServiceLifetime

* fix logger

* Update src/Orleans.Core/Lifecycle/ServiceLifetimeStage.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update test/NonSilo.Tests/ServiceLifetimeTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update test/NonSilo.Tests/ServiceLifetimeTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update test/NonSilo.Tests/ServiceLifetimeTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* xml doc fix

* Make NotifyCompleted idempotent

Prevent duplicate NotifyCompleted calls from re-executing callbacks by awaiting the existing completion task.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Rename service lifetime APIs to lifecycle

Use lifecycle terminology across PR dotnet#9792 types, registrations, files, and tests while preserving behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Reuben Bond <reuben.bond@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add externally accessible lifecycle events for silos

4 participants