Skip to content

[API Proposal]: HttpRequestOptions should implement IReadOnlyDictionary #68149

Closed

Description

@Grauenwolf

Background and motivation

Methods and extension methods that don't modify a dictionary often expect a parameter of IReadOnlyDictionary instead of IDictionary.

API Proposal

namespace System.Net.Http
{
    public class HttpRequestOptions : IReadOnlyDictionary<string,object>, // NEW
                                      IDictionary<string, object> // EXISTING
    {
          [...]
    }
}

API Usage

var dic = (IReadOnlyDictionary<string,object>)request.Options;

Alternative Designs

No response

Risks

In rare circumstances, a method will have an overload for IDictionary and another overload for IReadOnlyDictionary. This would be ambiguous for HttpRequestOptions, as it is for other dictionaries.

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Apr 18, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Apr 18, 2022
  3. karelz commented on Apr 21, 2022

    @karelz
    Member

    Triage: IReadOnlyDictionary is strict subset of already implemented IDictionary, so the work is minimal. We wouldn't mind having both interfaces, unless it brings some known problems in general (API review to advise here).
    BTW: The type HttpRequestOptions was introduced in .NET 5.

  4. modified the milestones: 7.0.0, Future on Apr 21, 2022
  5. added
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    and removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    untriagedNew issue has not been triaged by the area owner
    on Apr 21, 2022
  6. bartonjs commented on May 11, 2023

    @bartonjs
    Member

    Looks good as proposed.

    We discussed the risks inherent to being both IDictionary and IReadOnlyDictionary (namely, being an ambiguous target for overloading). But we generally think that the risk is low, and the workaround (casting to one of the two interfaces) is easy.

    namespace System.Net.Http
    {
        public class HttpRequestOptions :
    +        IReadOnlyDictionary<string,object>,
             IDictionary<string, object>
        {
        }
    }
  7. added
    api-approvedAPI was approved in API review, it can be implemented
    and removed
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    on May 11, 2023
  8. added
    help wanted[up-for-grabs] Good issue for external contributors
    on May 11, 2023
  9. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 31, 2023
  10. added a commit that references this issue on Jun 1, 2023
    f9b3953
  11. added a commit that references this issue on Jun 21, 2023
    19a088e
  12. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 21, 2023
  13. modified the milestones: Future, 8.0.0 on Jul 3, 2023
  14. ghost locked as resolved and limited conversation to collaborators on Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Net.Httphelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions