I have an API client generated by NSwagStudio. My constructor for one of my endpoints looks like this:
private string _baseUrl = "http://localhost:11957";
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;
public AccountClient(System.Net.Http.HttpClient httpClient)
{
_httpClient = httpClient;
_settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(() =>
{
var settings = new Newtonsoft.Json.JsonSerializerSettings();
UpdateJsonSerializerSettings(settings);
return settings;
});
}
public string BaseUrl
{
get { return _baseUrl; }
set { _baseUrl = value; }
}
About 5 of these clients are generated. Obviously for production environments I want my API endpoint to be different. At the moment I use compiler hints (#if debug) to set either local or production endpoints.
Because all 5 of these clients get dependency injected as a singleton, is there an easy way to configure the BaseUrl for all 5 of these clients to use? I know I can just set BaseUrl early on across all 5 clients but I feel like there's gotta be an easier way to accomplish that then just copy pasta.
Thanks!
EDIT: In NSwagStudio I've tried to create a "configuration class" but couldn't easily see how to use it or apply it to this scenario.