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
It appears interface composition now is possible, but is undocumented. I think this would help a population of folks that have larger API surfaces they are trying to create / maintain with Refit.
Interface Composition provides a better UX as you can dive into sub-concerns and not have a globally inherited interface where intellisense, etc is returning everything all the time.
Describe the solution you'd like
Document Refit interface composition.
Describe alternatives you've considered
n/a, it now works (at least with HttpClientFactory)
Describe suggestions on how to achieve the feature
Please see my below code example:
publicinterfaceIMainApi{IUsersApiUsers{get;}IApplicationsApiApplications{get;}// could have many more}publicinterfaceIUsersApi{[Get("/users")]Task<object>GetUsers();}publicinterfaceIApplicationsApi{[Get("/applications")]Task<object>GetApplications();}internalrecordMainApi(IUsersApiUsers,IApplicationsApiApplications):IMainApi;publicstaticclassDISetup{privatestaticreadonlyRefitSettings_settings=new(){// don't set the primary handler or anything like that that refit would invoke multiple times};publicstatic IHttpClientBuilder AddMainApiClient(thisIServiceCollectionservices,UribaseAddress){
services.AddSingleton<IMainApi,MainApi>();varmainBuilder= services.AddRefitClient<IUsersApi>((services)=> _settings, nameof(IMainApi));//using the same name here causes the underlying http client to be shared
services.AddRefitClient<IApplicationsApi>((services)=> _settings, nameof(IMainApi));
mainBuilder.ConfigureHttpClient(client =>{ client.BaseAddress =baseAddress;});returnmainBuilder;}}
The text was updated successfully, but these errors were encountered:
I'd like to re-visit the solutioning / documentation around interface composition on latest .NET 8 and
Refit.HttpClientFactory
7.Related to: #49
It appears interface composition now is possible, but is undocumented. I think this would help a population of folks that have larger API surfaces they are trying to create / maintain with Refit.
Interface Composition provides a better UX as you can dive into sub-concerns and not have a globally inherited interface where intellisense, etc is returning everything all the time.
Describe the solution you'd like
Document Refit interface composition.
Describe alternatives you've considered
n/a, it now works (at least with HttpClientFactory)
Describe suggestions on how to achieve the feature
Please see my below code example:
The text was updated successfully, but these errors were encountered: