-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-DependencyInjectionuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Background and motivation
Current default behavior allows for transient service registrations to implement IDisposable/IAsyncDisposable. As pointed out in other issues like #36461 that can cause memory leaks as a result instances being kept alive by the ServiceProvider until it gets disposed.
This proposal provides an alternative to #36461 and follows the pattern of ValidateScopes as introduced in aspnet/DependencyInjection#88
This proposal would work side by side with the latest proposal in #36461 as with that proposal an externally owned instance would not be captured.
API Proposal
namespace Microsoft.Extensions.DependencyInjection
{
public class ServiceProviderOptions
{
/// <summary>
/// <c>true</c> to perform check verifying that transient services would never get captured because they are disposable; otherwise <c>false</c>.
/// </summary>
public bool ValidateDisposables { get; set; }
}
}API Usage
new ServiceProviderOptions() { ValidateDisposables = true; }Alternative Designs
Provide more extensive apis for validation as proposed by #119646
Risks
Low risk opt-in addition.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-DependencyInjectionuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner