mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
26 lines
822 B
C#
26 lines
822 B
C#
using DataAccessLayer.Sql;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace WebAPI.Infrastructure
|
|
{
|
|
public class DefaultSqlConnectionFactory : ISqlConnectionFactory
|
|
{
|
|
private readonly string _connectionString;
|
|
|
|
public DefaultSqlConnectionFactory(IConfiguration configuration)
|
|
{
|
|
_connectionString =
|
|
Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")
|
|
?? configuration.GetConnectionString("Default")
|
|
?? throw new InvalidOperationException(
|
|
"Database connection string not configured. Set DB_CONNECTION_STRING env var or ConnectionStrings:Default."
|
|
);
|
|
}
|
|
|
|
public SqlConnection CreateConnection()
|
|
{
|
|
return new SqlConnection(_connectionString);
|
|
}
|
|
}
|
|
}
|