Background and Motivation
InputFile previously used explicit interface implementation for IDisposable.Dispose(), making it difficult for derived classes to properly dispose resources without reflection. A user implementing a derived class for handling cancel events (see #58118) had to use reflection to dispose _jsCallbacksRelay. The standard .NET dispose pattern with protected virtual void Dispose(bool) enables derived classes to extend disposal behavior cleanly.
Source: PR #64771, fixes #64392 (also references #58118).
Proposed API
namespace Microsoft.AspNetCore.Components.Forms;
public class InputFile : ComponentBase, IDisposable
{
+ protected virtual void Dispose(bool disposing);
}
Usage Examples
public class CustomInputFile : InputFile
{
private SomeResource _resource;
protected override void Dispose(bool disposing)
{
if (disposing)
{
_resource?.Dispose();
}
base.Dispose(disposing);
}
}
Alternative Designs
Keep explicit IDisposable.Dispose() and require reflection for derived classes. This was rejected as it violates the .NET dispose pattern guidelines.
Risks
Technically a behavioral change — existing derived classes that shadow Dispose() may behave differently. However, this follows established .NET patterns (InputBase, ValidationMessage already use this pattern).
Background and Motivation
InputFilepreviously used explicit interface implementation forIDisposable.Dispose(), making it difficult for derived classes to properly dispose resources without reflection. A user implementing a derived class for handling cancel events (see #58118) had to use reflection to dispose_jsCallbacksRelay. The standard .NET dispose pattern withprotected virtual void Dispose(bool)enables derived classes to extend disposal behavior cleanly.Source: PR #64771, fixes #64392 (also references #58118).
Proposed API
namespace Microsoft.AspNetCore.Components.Forms; public class InputFile : ComponentBase, IDisposable { + protected virtual void Dispose(bool disposing); }Usage Examples
Alternative Designs
Keep explicit
IDisposable.Dispose()and require reflection for derived classes. This was rejected as it violates the .NET dispose pattern guidelines.Risks
Technically a behavioral change — existing derived classes that shadow
Dispose()may behave differently. However, this follows established .NET patterns (InputBase,ValidationMessagealready use this pattern).