Repository Nuget: https://www.nuget.org/packages/braspin_environment_variable_dotnet
dotnet add package braspin_environment_variable_dotnet --version 0.1.10
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_BOOLEAN", true)]
public bool Boolean { get; set; } = false;
[EnvironmentVariable("VARIABLE_LONG", 10000000)]
public long Long { get; set; }
[EnvironmentVariable("VARIABLE_STRING", "Title")]
public string? String { get; set; }
[EnvironmentVariable("VARIABLE_DOUBLE", 5.1)]
public double Double { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
services.AddEnvironmentVariable<AppSettings>();
//...
}
//...
private readonly AppSettings _config;
public WeatherForecastController(AppSettings config)
{
_config = config;
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_BOOLEAN")]
public bool Boolean { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_BOOLEAN", true)]
public bool Boolean { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG")]
public long Long { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG", 100)]
public long Long { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG", 100, 0, 200)]
public long Double { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE")]
public double Double { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE", 10.1)]
public double Double { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE", 10.1, 0, 20)]
public double Double { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING")]
public string String { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING", "Title")]
public string String { get; set; };
}
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LOG_LEVEL", "Info", new string[]{"Trace", "Debug", "Info", "Warning", "Error"})]
public string LogLevel { get; set; };
}