2024-09-09 10:00:49 -07:00

27 lines
906 B
C#

using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using System.Data;
namespace FabApprovalWorkerService.Services;
public interface IDbConnectionService {
IDbConnection GetConnection();
}
public class DbConnectionService : IDbConnectionService {
private readonly string _envName;
private readonly string _dbConnectionString;
public DbConnectionService() {
_envName = Environment.GetEnvironmentVariable("FabApprovalEnvironmentName") ??
throw new ArgumentNullException("FabApprovalEnvironmentName environment variable not found");
_dbConnectionString = Environment.GetEnvironmentVariable("FabApprovalDbConnectionString") ??
throw new ArgumentNullException("FabApprovalDbConnectionString environment variable not found");
}
public IDbConnection GetConnection() {
return new SqlConnection(_dbConnectionString);
}
}