-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
37 lines (31 loc) · 1.17 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using CatConsult.EnvConfigurationProvider;
using CatConsult.EnvConfigurationProvider.Models;
using Microsoft.Extensions.Options;
using WebSample.Options;
var builder = WebApplication.CreateBuilder(args);
if (builder.Environment.IsDevelopment())
{
builder.Configuration
.AddEnvs(config => config
.AddRequiredEnv("GREETING_FORMAT", "Greeting:Format")
.AddOptionalEnv("GREETING_NAME", "Greeting:Name", "EnvConfigurationProvider")
.AddCustomMapper(envs => new ConfigurationEntry(
"ConnectionStrings:DefaultConnection",
$"Server={envs["DB_HOST"]};Port={envs["DB_PORT"]};Database={envs["DB_DATABASE"]};User Id={envs["DB_USER"]};Password={envs["DB_PASSWORD"]};"
))
);
}
builder.Services
.AddOptions<GreetingOptions>()
.BindConfiguration("Greeting")
.ValidateDataAnnotations()
.ValidateOnStart();
var app = builder.Build();
app.MapGet("/", (IConfiguration config, IOptions<GreetingOptions> options) =>
new
{
Greeting = string.Format(options.Value.Format, options.Value.Name),
Database = config.GetConnectionString("DefaultConnection"),
}
);
app.Run();