When debugging only app.Services.GetRequiredService<IPCRBService>(); Injected AppSettings instead of using GetEnvironmentVariable at Services level Get ready to use VSCode IDE
22 lines
534 B
C#
22 lines
534 B
C#
using System.Data;
|
|
|
|
using MesaFabApproval.Models;
|
|
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace MesaFabApproval.API.Services;
|
|
|
|
public interface IDbConnectionService {
|
|
IDbConnection GetConnection();
|
|
}
|
|
|
|
public class DbConnectionService : IDbConnectionService {
|
|
private readonly string _dbConnectionString;
|
|
|
|
public DbConnectionService(AppSettings appSettings) {
|
|
_dbConnectionString = appSettings.DbConnectionString;
|
|
}
|
|
|
|
public IDbConnection GetConnection() =>
|
|
new SqlConnection(_dbConnectionString);
|
|
} |