Skip to content

Add per-train lifecycle hook overrides on ServiceTrain#39

Merged
Theauxm merged 2 commits intomainfrom
feat/train-level-lifecycle-hooks
Mar 19, 2026
Merged

Add per-train lifecycle hook overrides on ServiceTrain#39
Theauxm merged 2 commits intomainfrom
feat/train-level-lifecycle-hooks

Conversation

@Theauxm
Copy link
Copy Markdown
Member

@Theauxm Theauxm commented Mar 19, 2026

Summary

  • Adds protected virtual OnStarted, OnCompleted, OnFailed, and OnCancelled methods to ServiceTrain so individual trains can override them without registering a global ITrainLifecycleHook
  • Global hooks fire first, then train-level overrides; exceptions in overrides are caught and logged
  • 17 new tests covering all hooks, ordering, error swallowing, partial overrides, defaults, and CancellationToken forwarding

Test plan

  • All 17 new TrainLifecycleOverrideTests pass (InMemory provider)
  • All 48 existing LifecycleHookRunnerTests and AddLifecycleHookTests still pass
  • Zero build warnings

Theauxm added 2 commits March 19, 2026 15:48
Adds protected virtual OnStarted, OnCompleted, OnFailed, and OnCancelled
methods to ServiceTrain. Individual trains can override these to react to
their own lifecycle events without registering a global ITrainLifecycleHook.

Global hooks fire first, then train-level overrides. Exceptions in overrides
are caught and logged, matching the global hook error handling pattern.
…kFactory

AddLifecycleHook<T>() now accepts either ITrainLifecycleHook or
ITrainLifecycleHookFactory directly. When given a hook type, a generic
LifecycleHookFactory<T> is created internally — no need for hand-written
factory classes. Removes BroadcastLifecycleHookFactory in favor of the
generic factory.
@Theauxm Theauxm merged commit d121ac2 into main Mar 19, 2026
1 check passed
@Theauxm Theauxm deleted the feat/train-level-lifecycle-hooks branch March 19, 2026 21:51
@traxsharp
Copy link
Copy Markdown

traxsharp Bot commented Mar 19, 2026

This PR is included in version 1.24.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant