Commit Inicial: Se definen tecnologías y modelos de datos.
This commit is contained in:
23
backend/Data/DapperContext.cs
Normal file
23
backend/Data/DapperContext.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user