Add warning for ABP modules not in the [DependsOn] chain#25223
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
AbpModuletypes. - 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. |
- 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
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
EngincanV
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 causesLazyServiceProviderto remainnull, leading toNullReferenceExceptionat runtime — a problem that is very hard to diagnose.This change logs a warning at startup when this misconfiguration is detected:
Detection is lightweight — only checks assemblies where property injection was actually skipped during registration. No
AppDomainscanning.