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
There are currently no overloads in the dependency injection that allow resolving the base uri from a service.
For example, the code I have now before using this library registers an http client like so, where it resolves the base url out of a configuration object.
services.AddHttpClient(MyAppClient.HttpClientName,(sp,client)=>{varconfig=sp.GetRequiredService<IMyAppConfiguration>();if(config.BaseUrl==null)thrownewInvalidOperationException("MyApp:BaseUrl must be configured");client.BaseAddress=newUri(config.BaseUrl);
This gives me control to change the base url from config without having to resolve a configuration object during service collection registration.
I would propose that this file be amended to have an overload like so:
publicstaticRestClientFactoryConfigAddRestClient(thisIServiceCollectionservices,stringname,Func<IServiceProvider,string>baseUriLoader,HeadersdefaultRequestHeaders){if(string.IsNullOrWhiteSpace(name))thrownewArgumentException("name cannot be empty",nameof(name));services.TryAddSingleton<IRestClientFactory,RestClientFactory>();varhttpClientBuilder=services.AddHttpClient(name);varconfig=newRestClientFactoryConfig(httpClientBuilder);services.AddSingleton(serviceProvider =>newRestClientContainer(serviceProvider,name,baseUriLoader(serviceProvider),defaultRequestHeaders));returnconfig;}
As well as other overloads for making name and headers optional.
Which would then allow a registration like so:
services.AddRestClient(sp =>{varconfig=sp.GetRequiredService<IMyAppConfiguration>();if(config.BaseUrl==null)thrownewInvalidOperationException("MyApp:BaseUrl must be configured");returnconfig.BaseUrl;});
Thanks!
The text was updated successfully, but these errors were encountered:
DrLeh
added a commit
to DrLeh/DalSoft.RestClient
that referenced
this issue
Aug 11, 2021
Untested! Changes made in github web UI mostly as a guideline of suggestions. I might have gotten some of the calls to other overloads wrong as it's hard to tell without IDE
Update: see #104
There are currently no overloads in the dependency injection that allow resolving the base uri from a service.
For example, the code I have now before using this library registers an http client like so, where it resolves the base url out of a configuration object.
This gives me control to change the base url from config without having to resolve a configuration object during service collection registration.
DalSoft.RestClient/DalSoft.RestClient/DependencyInjection/ServiceCollectionExtensions.cs
Lines 24 to 35 in f8b29fb
I would propose that this file be amended to have an overload like so:
As well as other overloads for making name and headers optional.
Which would then allow a registration like so:
Thanks!
The text was updated successfully, but these errors were encountered: