4.7 KiB
BUG-006: Dependency Injection Failure - IApplicationDbContext Not Registered
Severity
CRITICAL (P0) - Application Cannot Start
Status
OPEN - Discovered during Docker validation after BUG-005 fix
Priority
P0 - Fix Immediately - Blocks all development work
Discovery Date
2025-11-05
Environment
- Docker environment
- Release build
- .NET 9.0
Summary
The application fails to start due to a missing dependency injection registration. The IApplicationDbContext interface is not registered in the DI container, causing all Sprint command handlers to fail validation at application startup.
Root Cause Analysis
Problem
The ModuleExtensions.cs file (used in Program.cs) registers the PMDbContext but does NOT register the IApplicationDbContext interface that Sprint command handlers depend on.
Affected Files
- c:\Users\yaoji\git\ColaCoder\product-master\colaflow-api\src\ColaFlow.API\Extensions\ModuleExtensions.cs
- Lines 39-46: Only registers
PMDbContext, missing interface registration
- Lines 39-46: Only registers
Comparison
Correct Implementation (in ProjectManagementModule.cs - NOT USED):
// Line 44-45
// Register IApplicationDbContext
services.AddScoped<IApplicationDbContext>(sp => sp.GetRequiredService<PMDbContext>());
Broken Implementation (in ModuleExtensions.cs - CURRENTLY USED):
// Lines 39-46
services.AddDbContext<PMDbContext>((serviceProvider, options) =>
{
options.UseNpgsql(connectionString);
var auditInterceptor = serviceProvider.GetRequiredService<AuditInterceptor>();
options.AddInterceptors(auditInterceptor);
});
// ❌ MISSING: IApplicationDbContext registration!
Steps to Reproduce
- Clean Docker environment:
docker-compose down -v - Build backend image:
docker-compose build backend - Start services:
docker-compose up -d - Check backend logs:
docker-compose logs backend
Expected Behavior
- Application starts successfully
- All dependencies resolve correctly
- Sprint command handlers can be constructed
Actual Behavior
Application crashes at startup with:
System.AggregateException: Some services are not able to be constructed
System.InvalidOperationException: Unable to resolve service for type 'ColaFlow.Modules.ProjectManagement.Application.Common.Interfaces.IApplicationDbContext'
while attempting to activate 'ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateSprint.UpdateSprintCommandHandler'
Affected Components
All Sprint command handlers fail to construct:
UpdateSprintCommandHandlerStartSprintCommandHandlerRemoveTaskFromSprintCommandHandlerDeleteSprintCommandHandlerCreateSprintCommandHandlerCompleteSprintCommandHandlerAddTaskToSprintCommandHandler
Impact
- Application cannot start - Complete blocker
- Docker environment unusable - Frontend developers cannot work
- All Sprint functionality broken - Even if app starts, Sprint CRUD would fail
- Development halted - No one can develop or test
Fix Required
Add the missing registration to ModuleExtensions.cs:
// In AddProjectManagementModule method, after line 46:
// Register IApplicationDbContext interface
services.AddScoped<ColaFlow.Modules.ProjectManagement.Application.Common.Interfaces.IApplicationDbContext>(
sp => sp.GetRequiredService<PMDbContext>());
Alternative Fix (Better Long-term)
Consider using the ProjectManagementModule class (which has correct registration) instead of duplicating logic in ModuleExtensions.cs. This follows the Single Responsibility Principle and reduces duplication.
Test Plan (After Fix)
- Local compilation:
dotnet build- should succeed - Docker build:
docker-compose build backend- should succeed - Docker startup:
docker-compose up -d- all containers should be healthy - Backend health check:
curl http://localhost:5000/health- should return "Healthy" - Verify logs: No DI exceptions in backend logs
- API smoke test: Access Swagger UI at
http://localhost:5000/scalar/v1
Related Bugs
- BUG-005 (Compilation error) - Fixed
- This bug was discovered after BUG-005 fix during Docker validation
Notes
- This is a runtime bug, not a compile-time bug
- The error only appears when ASP.NET Core validates the DI container at startup (line 165 in Program.cs:
var app = builder.Build();) - Local development might not hit this if developers use different startup paths
- Docker environment exposes this because it validates all services on startup
QA Recommendation
NO GO - Cannot proceed with Docker environment delivery until this is fixed.
Severity Justification
- Critical because application cannot start
- P0 because it blocks all development work
- Immediate fix required - no workarounds available