fix: simplify database connection string handling in Program.cs #3
This commit is contained in:
@@ -48,14 +48,11 @@ namespace Api
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Add DbContext with SQL Server
|
||||
// Allow connection string to be set via environment variable (e.g., in Docker)
|
||||
var envConnectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING");
|
||||
var connectionString = !string.IsNullOrWhiteSpace(envConnectionString)
|
||||
? envConnectionString
|
||||
: builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseSqlServer(connectionString));
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
Reference in New Issue
Block a user