Fix: transient disposable detection misses IAsyncDisposable-only services - #33
Merged
Merged
Conversation
…able Co-authored-by: AGiorgetti <246067+AGiorgetti@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix detection of IAsyncDisposable-only transient services
Fix: transient disposable detection misses IAsyncDisposable-only services
Feb 26, 2026
AGiorgetti
approved these changes
Feb 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug in the transient disposable detection feature where services implementing only IAsyncDisposable (without IDisposable) were not detected, potentially causing memory leaks when resolved from the root scope.
Changes:
- Introduced
IsDisposableTypehelper method that checks bothIDisposableandIAsyncDisposableinterfaces - Updated all registration-time type checks to use the new helper method
- Updated all runtime checks in factory descriptors to detect both disposal interfaces
- Added comprehensive test coverage for
IAsyncDisposable-only services including type-based, factory-based, and keyed service scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Mammoth.Extensions.DependencyInjection/DetectIncorrectUsageOfTransientDisposables.cs | Added IsDisposableType helper and updated all disposable type checks to cover both IDisposable and IAsyncDisposable |
| src/Mammoth.Extensions.DependencyInjection.Tests/DetectIncorrectUsageOfTransientDisposablesTests.cs | Added test fixtures and six test methods covering type-based, factory-based, and keyed scenarios for IAsyncDisposable-only services |
Contributor
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: AGiorgetti <246067+AGiorgetti@users.noreply.github.com>
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.
PatchForDetectIncorrectUsageOfTransientDisposablesto checkIAsyncDisposablein open generic checkPatchForDetectIncorrectUsageOfTransientDisposablesswitch case for type-based descriptors to checkIAsyncDisposableCreatePatchedFactoryDescriptorto detectIAsyncDisposableat runtimeCreatePatchedKeyedFactoryDescriptorto detectIAsyncDisposableat runtimeIsDisposableTypehelper to avoid repetitionTransientAsyncDisposable,AsyncDisposableConsumer,AsyncDisposableConsumerFactorytest fixturesGetDisposablesassertions)GetDisposablesassertions)Original prompt
IAsyncDisposable-only services #21💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.