Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

Implement dispose pattern for InputFile

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Implement standard .NET dispose pattern in InputFile

Description

InputFile previously used explicit interface implementation for IDisposable.Dispose(), making it difficult for derived classes to properly dispose resources without reflection. Now implements the standard dispose pattern with a protected virtual method.

Changes:

  • Add protected virtual void Dispose(bool disposing) method containing disposal logic
  • Update IDisposable.Dispose() to call Dispose(true)
  • Add unit test verifying derived classes can override disposal behavior
  • Update public API surface

Pattern follows:

protected virtual void Dispose(bool disposing)
{
    if (disposing)
    {
        _jsCallbacksRelay?.Dispose();
    }
}

void IDisposable.Dispose()
{
    Dispose(disposing: true);
}

Derived classes can now override Dispose(bool) without reflection, consistent with InputBase and ValidationMessage.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Blazor] InputFile should implement dispose pattern</issue_title>
<issue_description>I implemented a derived class of InputFile for handling the cancel event (see also #58118).
I had to use reflection to dispose _jsCallbacksRelay. InputFile should implement the dispose pattern to make it easier for derived classes to properly dispose of resources.</issue_description>

<agent_instructions>Use the Microsoft docs to learn how to properly implement the Dispose pattern inside InputFile and do so.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@dotnet-policy-service
Copy link
Contributor

Greetings! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

Copilot AI changed the title [WIP] Implement dispose pattern in InputFile class Implement dispose pattern for InputFile Dec 15, 2025
Copilot AI requested a review from javiercn December 15, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] InputFile should implement dispose pattern

2 participants