You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When this library is used by applications with dependency injection configured, HttpClients should be created with the IHttpClientFactory. But our TodoistRestClient keeps creating new instances of HttpClient every time it is instantiated, which is not recommended.
I suggest then we add the option to use IHttpClientFactory when it's available by making the following changes:
Add a constructor overload for TodoistRestClient that takes an HttpClient instance as an argument:
Create an ITodoistClientFactory interface and TodoistClientFactory implementation to inject into the DI container, and use the provided IHttpClientFactory:
In other services (e.g. asp.net core controllers):
publicclassExampleController:Controller{privatereadonlyITodoistClientFactory_todoistClientFactory;publicExampleController(ITodoistClientFactorytodoistClientFactory){_todoistClientFactory=todoistClientFactory;}publicIActionResultExampleAction(){ITodoistClientclient=_todoistClientFactory.CreateClient("API token");// Use the client to interact with the Todoist API.//...}}
The text was updated successfully, but these errors were encountered:
When this library is used by applications with dependency injection configured,
HttpClients
should be created with theIHttpClientFactory
. But ourTodoistRestClient
keeps creating new instances ofHttpClient
every time it is instantiated, which is not recommended.I suggest then we add the option to use
IHttpClientFactory
when it's available by making the following changes:TodoistRestClient
that takes anHttpClient
instance as an argument:ITodoistClientFactory
interface andTodoistClientFactory
implementation to inject into the DI container, and use the providedIHttpClientFactory
:ITodoistClientFactory
andIHttpClientFactory
:That way, our
TodoistClient
can be instantiated the same way asHttpClient
, using the factory pattern.Usage:
program.cs
):The text was updated successfully, but these errors were encountered: