A solution for khellang/Scrutor#180 baked into a Nuget Package
- Inject your Http Client as a named Client
- Make sure that all your Api Clients are assignable to a common interface
- Register all your Api Clients with Scrutor.Extensions.HttpClient
/* Inject named HttpClient */
services.AddHttpClient("MyHttpClient", client =>
{
client.BaseAddress = new Uri("https://api.example.com");
});
/* Inject all implementations of IMyHttpApiClient */
services.Scan(scan => scan
.FromCallingAssembly()
.AddClasses(classes => classes.AssignableTo<IMyHttpApiClient>())
.AsMatchingInterface()
.AsHttpClient("MyHttpClient")
);