PI06 i PI06-1. Docker definitions for MSSQL and Postgres. Data seeder/generator for countries and people. Entity Framework example with variants for Postgres and MSSQL

This commit is contained in:
Boris Milašinović
2026-04-19 16:49:07 +02:00
parent 44a663e170
commit 6f56d107a2
89 changed files with 7305 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
namespace Secrets;
public class Demo
{
public int Key0 { get; set; }
public string? Key1 { get; set; }
public string? Key2 { get; set; }
}

View File

@@ -0,0 +1,23 @@
using Microsoft.Extensions.Configuration;
using Secrets;
var enumerator = Environment.GetEnvironmentVariables().GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine($"{enumerator.Key} = {enumerator.Value}");
}
Console.WriteLine("----------------------------");
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json") //order is important!
.AddJsonFile("missing_one.json", optional: true) //
.AddEnvironmentVariables() // include Package Microsoft.Extensions.Configuration.EnvironmentVariables
.AddUserSecrets("PI-Secrets") //package Microsoft.Extensions.Configuration.UserSecrets
.Build();
Console.WriteLine($"Custom env variable using configuration = " + configuration["CustomEnvValue"]);
Console.WriteLine($"Name = " + configuration["Name"]);
Console.WriteLine($"Key0 = " + configuration["Demo:Key0"]); //or Demo__Key0
Demo? demo = configuration.GetSection("Demo").Get<Demo>(); // package Microsoft.Extensions.Configuration.Binder
Console.WriteLine($"Key1 = " + demo?.Key1);
Console.WriteLine($"Key2 = " + demo?.Key2);

View File

@@ -0,0 +1,10 @@
{
"profiles": {
"Secrets": {
"commandName": "Project",
"environmentVariables": {
"CustomEnvValue": "Demo"
}
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>PI</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.6" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
{
"Name": "Bob",
"Demo": {
"Key0": 123,
"Key1": "something that should not be publicly available"
}
}