Skip to content

Disable conventional registration of InMemoryDynamicBackgroundWorker#25355

Merged
salihozkara merged 2 commits intorel-10.3from
fix-inmemory-dynamic-bg-worker-conventional-registration
May 4, 2026
Merged

Disable conventional registration of InMemoryDynamicBackgroundWorker#25355
salihozkara merged 2 commits intorel-10.3from
fix-inmemory-dynamic-bg-worker-conventional-registration

Conversation

@maliming
Copy link
Copy Markdown
Member

@maliming maliming commented May 2, 2026

InMemoryDynamicBackgroundWorker is auto-registered as a Singleton because IBackgroundWorker derives from ISingletonDependency. Its constructor takes a string workerName parameter that DI cannot resolve, so any host that runs ServiceCollection validation (ASP.NET Core in Development with WebApplicationBuilder.Build() enabling ValidateOnBuild) crashes at startup.

Mark it [DisableConventionalRegistration] since the manager creates instances on demand via new.

InMemoryDynamicBackgroundWorker indirectly implements ISingletonDependency
via IBackgroundWorker, so conventional registration tries to register it
as a service. Its constructor takes a string workerName parameter that
the DI container cannot resolve, which crashes any host that runs
ServiceCollection validation (e.g. ASP.NET Core in Development, where
WebApplicationBuilder.Build() enables ValidateOnBuild). The dynamic worker
is created on demand by DefaultDynamicBackgroundWorkerManager and must
not be auto-registered, so mark it with [DisableConventionalRegistration].
Copilot AI review requested due to automatic review settings May 2, 2026 06:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 prevents InMemoryDynamicBackgroundWorker from being registered by ABP’s conventional DI scanning, avoiding ValidateOnBuild failures in Microsoft.Extensions.DependencyInjection when running without Autofac (notably ASP.NET Core Development defaults).

Changes:

  • Marked InMemoryDynamicBackgroundWorker with [DisableConventionalRegistration] so it’s not auto-registered as a singleton service.
  • Added a regression test ensuring the worker is absent from the service collection and that building a provider with ValidateOnBuild = true succeeds.

Reviewed changes

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

File Description
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker.cs Disables conventional registration to prevent DI validation from trying to construct the worker (unresolvable string workerName).
framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker_Registration_Tests.cs Regression test verifying the type is not registered and DI validation passes with ValidateOnBuild.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.80%. Comparing base (b809229) to head (cd3825b).
⚠️ Report is 12 commits behind head on rel-10.3.

Additional details and impacted files
@@             Coverage Diff              @@
##           rel-10.3   #25355      +/-   ##
============================================
+ Coverage     49.30%   49.80%   +0.49%     
============================================
  Files          3667     3609      -58     
  Lines        123121   120658    -2463     
  Branches       9404     9215     -189     
============================================
- Hits          60707    60094     -613     
+ Misses        60590    58760    -1830     
+ Partials       1824     1804      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maliming maliming added this to the 10.3-patch milestone May 2, 2026
@maliming maliming requested a review from salihozkara May 4, 2026 05:54
@salihozkara salihozkara merged commit 6812613 into rel-10.3 May 4, 2026
4 of 5 checks passed
@salihozkara salihozkara deleted the fix-inmemory-dynamic-bg-worker-conventional-registration branch May 4, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants