Skip to content

RE: DelegatingHandler disposable transient error #967

Description

@legion-gaming

This is in reference to: #183 posted back in 2016 that was closed by saying the solution was to register a handler as a singleton.

There are multiple reasons why you should not do this, but one of them being that handlers can be configurable so that they can be re-used with multiple http clients and configured on a per-client basis. Consider a handler called OAuthHandler where the constructor takes in IOptionsSnapshot<OAuthHandlerOptions>. This allows me to have two different HttpClient instances that can both use the same handler type to authenticate with two different OAuth endpoints by configuring each handler per the client's needs.

Another reason has to do with DNS changes which was one of the driving forces that IHttpClientFactory was intended to solve.

I don't believe, however, that making an alteration to ignore the DelegatingHandler type from the AddTransient call is the answer, because there could also be other exceptions to this rule for other things within the framework. Maybe this is a configuration that SimpleInjector can read in to know that "Here's a list of exceptions to the rule for disposing transients." or something to that effect.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions