Skip to content

Add warning for ABP modules not in the [DependsOn] chain#25223

Merged
EngincanV merged 4 commits into
rel-10.3from
warn-orphaned-abp-modules
Apr 9, 2026
Merged

Add warning for ABP modules not in the [DependsOn] chain#25223
EngincanV merged 4 commits into
rel-10.3from
warn-orphaned-abp-modules

Conversation

@maliming

@maliming maliming commented Apr 9, 2026

Copy link
Copy Markdown
Member

When an assembly contains an ABP module but is not part of the [DependsOn] chain, Autofac silently skips property injection for types in that assembly. This causes LazyServiceProvider to remain null, leading to NullReferenceException at runtime — a problem that is very hard to diagnose.

This change logs a warning at startup when this misconfiguration is detected:

Assembly 'Volo.Saas.Host.HttpApi' has services registered in the DI container, but its ABP module 'SaasHostHttpApiModule' is not in the [DependsOn] chain. Property injection (e.g. LazyServiceProvider) will not work for these types and may cause NullReferenceException at runtime. Add typeof(SaasHostHttpApiModule) to your module's [DependsOn] attribute to fix this.

Detection is lightweight — only checks assemblies where property injection was actually skipped during registration. No AppDomain scanning.

When a type's assembly contains an ABP module but is not part of the
module dependency chain, Autofac's property injection is silently
skipped. This causes LazyServiceProvider and other injected properties
to remain null, leading to NullReferenceException at runtime.

This change detects the misconfiguration at startup and logs a warning
with the affected assembly name, module type, and a fix suggestion.
Copilot AI review requested due to automatic review settings April 9, 2026 04:57
@maliming maliming added this to the 10.3-final milestone Apr 9, 2026

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

Adds a startup-time warning in the ABP Autofac integration to detect “orphaned” ABP modules: assemblies that have services registered but whose AbpModule isn’t in the [DependsOn] chain (which can lead to skipped property injection and runtime NREs).

Changes:

  • Track assemblies where property injection was skipped due to not being in the loaded module chain, and scan them after registration to warn about orphaned AbpModule types.
  • Extend the Autofac ABP registration pipeline to pass along the tracked-assembly set.
  • Add an integration test validating the warning behavior (warn for orphaned modules, don’t warn for loaded modules).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs Collects non-module assemblies and logs warnings for orphaned AbpModule types after registrations complete.
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs Passes a tracked-assemblies set into property-injection enabling logic and records assemblies when skipped.
framework/test/Volo.Abp.Autofac.Tests/Volo/Abp/Autofac/WarnForOrphanedAbpModules_Tests.cs Adds tests to assert warning emission for orphaned modules and absence for loaded modules.

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 8 out of 8 changed files in this pull request and generated 5 comments.

Comment thread framework/src/Volo.Abp.Core/Volo/Abp/Logging/IInitLoggerFactory.cs
Comment thread framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs Outdated
maliming added 2 commits April 9, 2026 14:23
- WriteInitLogs now uses ILoggerFactory to flush all InitLogger
  categories with their original category name instead of only
  flushing AbpApplicationBase
- Add CategoryName to AbpInitLogEntry, recorded automatically by
  DefaultInitLogger<T> using typeof(T).FullName
- Add GetAllEntries/ClearAllEntries to IInitLoggerFactory interface
- Add GetReferencedAssemblies filter to skip non-ABP assemblies
- Handle ReflectionTypeLoadException separately from other exceptions
- Add CategoryName null/empty fallback in WriteInitLogs
- Skip DisablePropertyInjection types from orphaned module detection
@maliming maliming requested a review from EngincanV April 9, 2026 06:42
@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 12 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (rel-10.3@c827a29). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ensions/DependencyInjection/AutofacRegistration.cs 75.60% 9 Missing and 1 partial ⚠️
...k/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs 77.77% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             rel-10.3   #25223   +/-   ##
===========================================
  Coverage            ?   50.71%           
===========================================
  Files               ?     3472           
  Lines               ?   117140           
  Branches            ?     8840           
===========================================
  Hits                ?    59407           
  Misses              ?    55925           
  Partials            ?     1808           

☔ 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.

@EngincanV EngincanV merged commit 2069c8b into rel-10.3 Apr 9, 2026
5 checks passed
@EngincanV EngincanV deleted the warn-orphaned-abp-modules branch April 9, 2026 07:41
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