16 lines
551 B
C#
16 lines
551 B
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace e_suite.API.Common.extensions;
|
|
|
|
public static class ConfigurationHelper
|
|
{
|
|
public static T? GetConfigValue<T>(this IConfiguration configuration, string environmentVariable, string key, T defaultValue)
|
|
{
|
|
var envVariable = Environment.GetEnvironmentVariable(environmentVariable);
|
|
|
|
if (!string.IsNullOrWhiteSpace(envVariable))
|
|
return (T?)Convert.ChangeType(envVariable, typeof(T));
|
|
|
|
return configuration.GetValue(key, defaultValue);
|
|
}
|
|
} |