Refactor: the project is now divided into a more clear structure, with **Infrastructure** and **Application** layers added. Refactor: configurations are split into sections for different layers. Fix: now EF Core related operations, such as migration, should be invoked in `OptixServe.Infrastructure`, with config file and data dir passed into `dotnet ef` command. See `OptixServe.Infrastructure/Utilites/DesignTimeDbContextFactory.cs` for details. Fix: EF migrations are ignored in gitignore on purpose in early development.
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace OptixServe.Infrastructure.Configuration;
|
|
|
|
public static class ConfigurationHelper
|
|
{
|
|
public static IConfigurationBuilder CreateDefaultBuilder(string basePath)
|
|
{
|
|
var aspEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
|
var netEnv = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
|
|
var env = aspEnv ?? netEnv ?? null;
|
|
|
|
var builder = new ConfigurationBuilder()
|
|
// .SetBasePath(Directory.GetCurrentDirectory())
|
|
.SetBasePath(basePath)
|
|
.AddJsonFile("appsettings.json", optional: true)
|
|
.AddJsonFile("config.json", optional: true);
|
|
|
|
if (env != null)
|
|
{
|
|
builder.AddJsonFile($"appsettings.{env}.json", optional: true)
|
|
.AddJsonFile($"config.{env}.json", optional: true);
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static IConfigurationBuilder CreateDefaultBuilder()
|
|
{
|
|
return CreateDefaultBuilder(Directory.GetCurrentDirectory());
|
|
}
|
|
}
|