GFramework/ai-plan/public/archive/microsoft-di-container-disposal/todos/microsoft-di-container-disposal-tracking.md
gewuyou 0ec8aa076b fix(core): 修复容器释放与基准资源泄漏
- 修复 MicrosoftDiContainer 的 IDisposable 释放逻辑、根 ServiceProvider 清理与释放后访问保护
- 更新 CQRS benchmarks 的容器 cleanup,并补齐 RequestStartupBenchmarks 的冷启动容器释放路径
- 补充 Core 容器生命周期回归测试并归档 issue 327 的 ai-plan topic
2026-05-06 19:08:48 +08:00

49 lines
2.3 KiB
Markdown

# MicrosoftDiContainer Disposal Tracking
## Goal
Fix issue `#327` by making `MicrosoftDiContainer` explicitly disposable, ensuring frozen service providers and lock
state are released deterministically, and updating CQRS benchmarks so every owned container is disposed in cleanup or
cold-start paths.
## Current Recovery Point
- Recovery point: `MDC-DISPOSE-RP-001`
- Phase: completed and ready to archive
- Focus:
- keep the final validated implementation and archive handoff concise
## Active Risks
- No active implementation blockers remain after validation.
## Completed In This Stage
- Extended `IIocContainer` to inherit `IDisposable` so callers holding the abstraction can release container-owned
resources explicitly.
- Implemented `MicrosoftDiContainer.Dispose()` with idempotent root-provider release, lock cleanup, state clearing, and
`ObjectDisposedException` guards for post-disposal access.
- Updated `Clear()` to dispose the currently built root provider before resetting container state.
- Added Core regression tests that verify resolved DI-owned singletons are disposed and that disposed containers reject
further registration, lookup, and scope creation.
- Fixed CQRS benchmark cleanup so every benchmark-owned `MicrosoftDiContainer` is disposed, including the temporary
cold-start container path in `RequestStartupBenchmarks`.
## Validation Target
- `python3 scripts/license-header.py --check`
- `dotnet test GFramework.Core.Tests -c Release --filter "FullyQualifiedName~MicrosoftDiContainer|FullyQualifiedName~IocContainerLifetimeTests"`
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
- `dotnet build GFramework.sln -c Release`
## Latest Validation Result
- `python3 scripts/license-header.py --check` passed on 2026-05-06.
- `dotnet test GFramework.Core.Tests/GFramework.Core.Tests.csproj -c Release --filter "FullyQualifiedName~MicrosoftDiContainer|FullyQualifiedName~IocContainerLifetimeTests"` passed on 2026-05-06 with `55` tests passed.
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release` passed on 2026-05-06 with `0 warnings` and `0 errors`.
- `dotnet build GFramework.sln -c Release` passed on 2026-05-06 with `0 warnings` and `0 errors`.
## Next Recommended Resume Step
Archive this topic under `ai-plan/public/archive/` and push the fix branch for review.