Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ServiceCollectionExtensions.cs to include overloads that rely on service provider #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ public static RestClientFactoryConfig AddRestClient(this IServiceCollection serv
}

public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, string name, string baseUri, Headers defaultRequestHeaders)
{
return AddRestClient(services, name, sp => baseUri, sp => defaultRequestHeaders);
}

public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, Func<IServiceProvider, string> baseUriLoader)
{
return AddRestClient(services, baseUriLoader, sp => (Headers) null);
}

public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, Func<IServiceProvider, string> baseUriLoader, Headers defaultRequestHeaders)
{
return services.AddRestClient(RestClientFactory.DefaultClientName, baseUriLoader, sp => defaultRequestHeaders);
}

public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, Func<IServiceProvider, string> baseUriLoader, Func<IServiceProvider, Headers> headerLoader)
{
return services.AddRestClient(RestClientFactory.DefaultClientName, baseUriLoader, headerLoader);
}

public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, string name, Func<IServiceProvider, string> baseUriLoader, Func<IServiceProvider, Headers> headerLoader)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("name cannot be empty", nameof(name));

Expand All @@ -30,7 +50,7 @@ public static RestClientFactoryConfig AddRestClient(this IServiceCollection serv
var httpClientBuilder = services.AddHttpClient(name);
var config = new RestClientFactoryConfig(httpClientBuilder);

services.AddSingleton(serviceProvider => new RestClientContainer(serviceProvider, name, baseUri, defaultRequestHeaders));
services.AddSingleton(serviceProvider => new RestClientContainer(serviceProvider, name, baseUriLoader(sp), headerLoader(sp)));

return config;
}
Expand Down