There is a bit of if-else-if going in within the code. Is there a construct which could come handy. Also the section names are very similar too
public string GetRestApiUrlFromHost()
{
var restApiUrl = string.Empty;
var HostUrl = Request.Host.Value;
var DevURL = _configuration.GetSection("DEV_API_URL").Value;
var QAURL = _configuration.GetSection("QA_API_URL").Value;
var ProdURL = _configuration.GetSection("PROD_API_URL").Value;
if (HostUrl.Contains(DevURL, StringComparison.CurrentCultureIgnoreCase))
{
restApiUrl = _configuration.GetSection("DEV_REST_API_URL").Value;
}
else if (HostUrl.Contains(QAURL, StringComparison.CurrentCultureIgnoreCase))
{
restApiUrl = _configuration.GetSection("QA_REST_API_URL").Value;
}
else if (HostUrl.Contains(ProdURL, StringComparison.CurrentCultureIgnoreCase))
{
restApiUrl = _configuration.GetSection("PROD_REST_API_URL").Value;
}
else
{
restApiUrl = _configuration.GetSection("Local_REST_API_URL").Value;
}
return restApiUrl;
}
Looks redundant to me. But cannot place it. Which would be the most ideal way to refactor this code?