Last active
October 19, 2023 08:44
-
-
Save bestpika/576fe7b96288965a242c2207069e61ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Configuration; | |
public class AppSettings | |
{ | |
static private readonly IConfiguration _config = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | |
.AddYamlFile("appsettings.yaml", optional: false, reloadOnChange: true) | |
.Build(); | |
public static string? ConnectionString(string name = "DefaultConnection") => _config.GetConnectionString(name); | |
public static string? GetSection(string path) => _config.GetSection(path).Value; | |
public static T? GetValue<T>(string path) => _config.GetValue<T>(path); | |
public static string? GetValue(string path) => _config.GetValue<string>(path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<RootNamespace>MailSender</RootNamespace> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
<PublishSingleFile>true</PublishSingleFile> | |
<SelfContained>true</SelfContained> | |
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> | |
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | |
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Include="appsettings.yaml" CopyToOutputDirectory="Always" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment