23 lines
739 B
C#
23 lines
739 B
C#
using Microsoft.Data.SqlClient;
|
|
using System.Data;
|
|
|
|
namespace Inventario.API.Data
|
|
{
|
|
public class DapperContext
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly string _connectionString;
|
|
|
|
public DapperContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
var connStr = _configuration.GetConnectionString("DefaultConnection");
|
|
if (connStr is null)
|
|
throw new ArgumentNullException(nameof(connStr), "ConnectionString 'DefaultConnection' no encontrada.");
|
|
_connectionString = connStr;
|
|
}
|
|
|
|
public IDbConnection CreateConnection()
|
|
=> new SqlConnection(_connectionString);
|
|
}
|
|
} |