chore: add hrynco common library solution
- add the standalone HrynCo.Common solution and projects - include the shared common library source and tests - add package metadata and a repo gitignore
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
namespace HrynCo.Common;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public static class ConfigurationFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Use for .NET Core Console applications.
|
||||
/// </summary>
|
||||
public static IConfigurationRoot CreateConfiguration()
|
||||
{
|
||||
return CreateConfiguration(AppContext.BaseDirectory);
|
||||
}
|
||||
|
||||
public static IConfigurationRoot CreateConfiguration(string basePath)
|
||||
{
|
||||
string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
|
||||
return CreateConfiguration(basePath, environmentName);
|
||||
}
|
||||
|
||||
public static IConfigurationRoot CreateConfiguration(string basePath, string environmentName)
|
||||
{
|
||||
if (!Directory.Exists(basePath))
|
||||
{
|
||||
throw new DirectoryNotFoundException(
|
||||
$"Directory {basePath} does not exist. Wrong value of the {nameof(basePath)} parameter.");
|
||||
}
|
||||
|
||||
return new ConfigurationBuilder()
|
||||
.SetBasePath(basePath)
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.AddJsonFile($"appsettings.{environmentName}.json", true, true)
|
||||
.AddJsonFile("local.settings.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user