https://github.com/braspin/braspin_environment_variable_dotnet
Simple Read Environment Variables Dotnet for Kubernetes (ConfigMap and Secrets)
https://github.com/braspin/braspin_environment_variable_dotnet
configmap docker environment-variables kubernetes reader secrets serialization
Last synced: 5 months ago
JSON representation
Simple Read Environment Variables Dotnet for Kubernetes (ConfigMap and Secrets)
- Host: GitHub
- URL: https://github.com/braspin/braspin_environment_variable_dotnet
- Owner: braspin
- Created: 2023-12-01T02:06:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-13T21:16:45.000Z (about 1 year ago)
- Last Synced: 2025-09-29T17:52:36.309Z (9 months ago)
- Topics: configmap, docker, environment-variables, kubernetes, reader, secrets, serialization
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Environment Variable Dotnet
Repository Nuget: https://www.nuget.org/packages/braspin_environment_variable_dotnet
## Install Nuget Package
`` dotnet add package braspin_environment_variable_dotnet --version 0.1.10 ``
### Example class lauchSettings.json
```json
{
"environmentVariables": {
"VARIABLE_BOOLEAN": "true",
"VARIABLE_LONG": "10",
"VARIABLE_STRING": "Test",
"VARIABLE_DOUBLE": "1.15",
"VARIABLE_ARRAY_STRING": "Item1,Item2"
}
}
```
### Example class AppSettings.cs inheriting IEnvironmentVariable
```csharp
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; }
[EnvironmentVariable("VARIABLE_ARRAY_STRING", ',', new string[]("Item1", "Item2"))]
public string[] StringArray { get; set; }
}
```
### Add Startup.cs
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddEnvironmentVariable();
//...
}
```
### Using in yours Controllers
```csharp
//...
private readonly AppSettings _config;
public WeatherForecastController(AppSettings config)
{
_config = config;
}
```
## Annotation Types
### Boolean variable without default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_BOOLEAN")]
public bool Boolean { get; set; };
}
```
### Boolean variable with default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_BOOLEAN", true)]
public bool Boolean { get; set; };
}
```
### Long variable without default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG")]
public long Long { get; set; };
}
```
### Long variable with default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG", 100)]
public long Long { get; set; };
}
```
### Long variable with default, min and max value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LONG", 100, 0, 200)]
public long Double { get; set; };
}
```
### Double variable without default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE")]
public double Double { get; set; };
}
```
### Double variable with default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE", 10.1)]
public double Double { get; set; };
}
```
### Double variable with default, min and max value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_DOUBLE", 10.1, 0, 20)]
public double Double { get; set; };
}
```
### String variable without default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING")]
public string String { get; set; };
}
```
### String variable with default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING", "Title")]
public string String { get; set; };
}
```
### String Array variable without default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING_ARRAY")]
public string[] StringArray { get; set; };
}
```
### String Array variable comma separator
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING_ARRAY", ',')]
public string[] StringArray { get; set; };
}
```
### String Array variable comma separator and with default value
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_STRING_ARRAY", ',', new string[]("Item1", "Item2"))]
public string[] StringArray { get; set; };
}
```
### String variable with default value and enums values
```csharp
public class AppSettings : IEnvironmentVariable
{
[EnvironmentVariable("VARIABLE_LOG_LEVEL", "Info", new string[]{"Trace", "Debug", "Info", "Warning", "Error"})]
public string LogLevel { get; set; };
}
```