31 lines
1.0 KiB
C#
31 lines
1.0 KiB
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() {
|
|
if (_envName.ToLower().Equals("development")) {
|
|
return new SqliteConnection(_dbConnectionString);
|
|
} else {
|
|
return new SqlConnection(_dbConnectionString);
|
|
}
|
|
}
|
|
}
|