Skip to content

Make recurring actions scoped instead of singleton - #12

Merged
johnkors merged 1 commit into
mainfrom
jk/scoped-recurring-actions
Sep 21, 2026
Merged

johnkors merged 1 commit into
mainfrom
jk/scoped-recurring-actions

Conversation

@johnkors

Copy link
Copy Markdown
Contributor
  • AddRecurrer registers T with AddScoped instead of AddSingleton
  • CronBackgroundService is now generic (CronBackgroundService) and creates a fresh DI scope per cron tick, resolving T from it before calling Process
  • lets a recurring action take scoped dependencies (e.g. MassTransit's IPublishEndpoint) directly in its constructor, instead of every action injecting IServiceScopeFactory and opening a scope by hand
  • the BackgroundService itself is still a long-lived singleton, as before — only the action instance is now scoped per invocation
  • IRecurringAction is no longer registered as an open multi-service (GetServices() no longer resolves anything); only the concrete T is registered now — source-breaking only for a consumer that was relying on that multi-registration, which nothing known does

AddRecurrer<T> now registers T with AddScoped instead of forcing every
IRecurringAction into a DI singleton. CronBackgroundService<T> creates a
fresh scope per cron tick and resolves T from it, so actions can take
scoped dependencies (e.g. MassTransit's IPublishEndpoint) directly in
their constructor instead of injecting IServiceScopeFactory and opening
a scope by hand.

IRecurringAction is no longer registered as an open multi-service
(GetServices<IRecurringAction>() no longer resolves anything); only the
concrete T is registered now.
@johnkors
johnkors merged commit e94833a into main Sep 21, 2026
2 checks passed
johnkors added a commit that referenced this pull request Sep 21, 2026
+semver: major

AddRecurrer<T>'s move from singleton to scoped registration (#12) breaks
any consumer holding a reference to a recurring action expecting it to
stay the same instance across ticks, or calling
GetServices<IRecurringAction>() (no longer registered as an open
multi-service - only the concrete T is). GitVersion's +semver: major
convention (no explicit config override in this repo, so its default
regex applies) picks this up for the next release.
johnkors added a commit that referenced this pull request Sep 21, 2026
…#13)

* ci: use NuGet OIDC trusted publishing instead of a long-lived API key

Same pattern as Slackbot.Net's Release.yml: NuGet/login exchanges GitHub's
OIDC token for a short-lived NuGet API key at publish time, so NUGETORGAPIKEY
no longer needs to be stored as a long-lived secret.

* ci: consolidate Release/PreRelease into one workflow with a prerelease toggle

Same shape as Slackbot.Net's Release.yml: a single workflow_dispatch input
picks the version scheme, and the GitHub release step is skipped for
prereleases - one workflow to run instead of two near-duplicates.

* docs: tag the scoped-recurring-actions change as a breaking release

+semver: major

AddRecurrer<T>'s move from singleton to scoped registration (#12) breaks
any consumer holding a reference to a recurring action expecting it to
stay the same instance across ticks, or calling
GetServices<IRecurringAction>() (no longer registered as an open
multi-service - only the concrete T is). GitVersion's +semver: major
convention (no explicit config override in this repo, so its default
regex applies) picks this up for the next release.
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