Add IServiceLifecycle interface with lifecycle hooks for client and silo#9792
Conversation
|
@ReubenBond addressed the comments, PTAL! WDYT about this, I am unsure, but lean more towards (a)waiting indefinitely
|
|
@ledjon-behluli I think relying on them respecting the CT is ok (even if not defensive) |
|
@ReubenBond Added proper tests & removed the toy/test console app. We should consider not having the P.s: I do not have a strong opinion on the matter of |
|
Yes please! |
There was a problem hiding this comment.
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
IServiceLifetimeandIServiceLifetimeStageinterfaces providing callback registration and cancellation token support ServiceLifetimeStageimplementation 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 |
a68a22a to
3fcc96a
Compare
|
@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 |
IServiceLifecycle interface with lifecycle hooks for client and silo
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: 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>
3568e14 to
686e017
Compare
… 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>

close #9771
Microsoft Reviewers: Open in CodeFlow