Skip to content

[RFC] RestClientFactory for better DI supportΒ #1791

Open
@alexeyzimarev

Description

@alexeyzimarev

Issue

When registering the client instance, the last registered client will be injected, if the client is registered as AddSingleton<RestClient>. The only way to work around this is to use typed clients or wrappers.

It works similarly to AddHttpClient, except that AddHttpClient registered HttpClient as a transient dependency, and uses the client factory behind the scenes to pool the message handlers.

It would be nice to support registering named instances, where each named instance has its own options. Then, resolving a particular client instance would be through the factory. It's also similar to IHttpClientFactory behaviour in that sense. It should also be possible to register typed clients the same way as it's done with IHttpClientFactory, where the type name of the typed client is used as the options name.

What's unclear

  • Should named RestClient instances be registered as singletons, or transient? Transient is more work (see the next point)
  • Should we use IHttpClientFactory behind the scenes to delegate the handler pooling work? It only makes sense if we decide to support the transient scope

Based on the decision for the above points, it would be possible to decide on the implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions