feat: add additional configuration from files

This commit is contained in:
Polianin Nikita 2024-01-26 19:30:41 +03:00
parent 8f334ae5c2
commit e6cc9437d5

View File

@ -6,9 +6,26 @@ namespace Mirea.Api.Endpoint;
public class Program public class Program
{ {
private static IConfigurationRoot ConfigureEnvironment()
{
EnvironmentManager.LoadEnvironment(".env");
var environmentVariables = Environment.GetEnvironmentVariables()
.OfType<DictionaryEntry>()
.ToDictionary(
entry => entry.Key.ToString() ?? string.Empty,
entry => entry.Value?.ToString() ?? string.Empty
);
var result = new ConfigurationBuilder().AddInMemoryCollection(environmentVariables!);
return result.Build();
}
public static void Main(string[] args) public static void Main(string[] args)
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddConfiguration(ConfigureEnvironment());
builder.Configuration.AddJsonFile(Settings.FilePath, optional: true, reloadOnChange: true);
// Add services to the container. // Add services to the container.