# 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 1. **c:\Users\yaoji\git\ColaCoder\product-master\colaflow-api\src\ColaFlow.API\Extensions\ModuleExtensions.cs** - Lines 39-46: Only registers `PMDbContext`, missing interface registration ### Comparison **Correct Implementation** (in ProjectManagementModule.cs - NOT USED): ```csharp // Line 44-45 // Register IApplicationDbContext services.AddScoped(sp => sp.GetRequiredService()); ``` **Broken Implementation** (in ModuleExtensions.cs - CURRENTLY USED): ```csharp // Lines 39-46 services.AddDbContext((serviceProvider, options) => { options.UseNpgsql(connectionString); var auditInterceptor = serviceProvider.GetRequiredService(); options.AddInterceptors(auditInterceptor); }); // ❌ MISSING: IApplicationDbContext registration! ``` ## Steps to Reproduce 1. Clean Docker environment: `docker-compose down -v` 2. Build backend image: `docker-compose build backend` 3. Start services: `docker-compose up -d` 4. 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: - `UpdateSprintCommandHandler` - `StartSprintCommandHandler` - `RemoveTaskFromSprintCommandHandler` - `DeleteSprintCommandHandler` - `CreateSprintCommandHandler` - `CompleteSprintCommandHandler` - `AddTaskToSprintCommandHandler` ## 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`: ```csharp // In AddProjectManagementModule method, after line 46: // Register IApplicationDbContext interface services.AddScoped( sp => sp.GetRequiredService()); ``` ## 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) 1. Local compilation: `dotnet build` - should succeed 2. Docker build: `docker-compose build backend` - should succeed 3. Docker startup: `docker-compose up -d` - all containers should be healthy 4. Backend health check: `curl http://localhost:5000/health` - should return "Healthy" 5. Verify logs: No DI exceptions in backend logs 6. 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