DbDapperFactory.Sqlite
0.1.0
Additional Details
deprecated
dotnet add package DbDapperFactory.Sqlite --version 0.1.0
NuGet\Install-Package DbDapperFactory.Sqlite -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DbDapperFactory.Sqlite" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbDapperFactory.Sqlite" Version="0.1.0" />
<PackageReference Include="DbDapperFactory.Sqlite" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DbDapperFactory.Sqlite --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DbDapperFactory.Sqlite, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DbDapperFactory.Sqlite@0.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DbDapperFactory.Sqlite&version=0.1.0
#tool nuget:?package=DbDapperFactory.Sqlite&version=0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DbDapperFactory
Factory + extensiones de DI para crear DbConnection nombradas y usarlas con Dapper.
¿Qué es DbDapperFactory?
DbDapperFactory es un conjunto de librerías que facilita la integración de múltiples bases de datos en aplicaciones .NET usando Dapper como ORM ligero. Proporciona:
- 🏭 Factory de conexiones nombradas: Define múltiples conexiones a diferentes bases de datos y accede a ellas por nombre.
- 📦 Inyección de dependencias (DI): Integración nativa con
Microsoft.Extensions.DependencyInjection. - 🗄️ Soporte multi-proveedor: SqlServer, PostgreSQL, MySQL, SQLite, Oracle.
- 🔌 Simple y ligero: Minimal overhead, máximo control sobre las conexiones.
Instalación
Instala el paquete Core y el/los paquetes del proveedor que vayas a usar:
dotnet add package DbDapperFactory.Core
dotnet add package DbDapperFactory.SqlServer
dotnet add package DbDapperFactory.Postgres
dotnet add package DbDapperFactory.MySql
dotnet add package DbDapperFactory.Sqlite
dotnet add package DbDapperFactory.Oracle
O desde NuGet Package Manager.
Uso Básico (DI + conexiones nombradas)
1. Configura en el startup
using DbDapperFactory;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Registra la factory y define tus conexiones
builder.Services
.AddDapperConnectionFactory()
.AddSqlServer("Main", configuration.GetConnectionString("Main")!)
.AddPostgres("Reporting", configuration.GetConnectionString("Reporting")!);
var app = builder.Build();
2. Inyecta y usa en tus servicios
using DbDapperFactory;
using Dapper;
public sealed class UsersRepository
{
private readonly IDapperConnectionFactory _connections;
public UsersRepository(IDapperConnectionFactory connections)
=> _connections = connections;
// Obtener usuario por ID
public async Task<User?> GetByIdAsync(Guid id)
{
using var conn = _connections.CreateConnection("Main");
return await conn.QuerySingleOrDefaultAsync<User>(
"select * from users where id = @id",
new { id });
}
// Listar usuarios
public async Task<List<User>> GetAllAsync()
{
using var conn = _connections.CreateConnection("Main");
var users = await conn.QueryAsync<User>("select * from users");
return users.ToList();
}
// Crear usuario
public async Task<int> CreateAsync(User user)
{
using var conn = _connections.CreateConnection("Main");
return await conn.ExecuteAsync(
"insert into users (id, name, email) values (@id, @name, @email)",
user);
}
}
// Modelo
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Ejemplos Avanzados
Múltiples bases de datos
// Configuración
services
.AddDapperConnectionFactory()
.AddSqlServer("Main", "Server=localhost;Database=MyApp;...")
.AddPostgres("Analytics", "Host=localhost;Database=Analytics;...")
.AddMySql("Legacy", "Server=localhost;Database=OldApp;...");
// Uso
public class ReportingService
{
private readonly IDapperConnectionFactory _connections;
public ReportingService(IDapperConnectionFactory connections)
=> _connections = connections;
public async Task<List<DailySales>> GetSalesFromAnalyticsAsync()
{
using var conn = _connections.CreateConnection("Analytics");
return (await conn.QueryAsync<DailySales>(
"select * from daily_sales where date >= @startDate",
new { startDate = DateTime.Now.AddDays(-30) })).ToList();
}
public async Task<List<LegacyUser>> GetUsersFromLegacyAsync()
{
using var conn = _connections.CreateConnection("Legacy");
return (await conn.QueryAsync<LegacyUser>(
"select * from users")).ToList();
}
}
Configuración personalizada por proveedor
// SQL Server con opciones
services
.AddDapperConnectionFactory()
.AddSqlServer(
"Main",
"Server=localhost;Database=MyApp;...",
configure: conn =>
{
conn.ConnectionTimeout = 30;
});
// PostgreSQL
services.AddPostgres(
"Reporting",
"Host=localhost;Database=Analytics;...");
// SQLite
services.AddSqlite(
"Cache",
"Data Source=cache.db;");
Notas Importantes
- ✅ La factory no abre la conexión automáticamente. Tú controlas cuándo llamar a
Open()/OpenAsync(). - ✅ Cada llamada a
CreateConnection(name)crea una instancia nueva de conexión. - ✅ Usa
usingpara asegurar que la conexión se cierre y disponga correctamente. - ✅ Compatible con Dapper para queries, inserts, updates, deletes y procedimientos almacenados.
Características
| Característica | Detalles |
|---|---|
| Inyección de Dependencias | Integrada con IServiceCollection |
| Conexiones Nombradas | Define múltiples conexiones y accede por nombre |
| Multi-Proveedor | SqlServer, PostgreSQL, MySQL, SQLite, Oracle |
| Async/Await | Compatible con operaciones asincrónicas |
| Dapper Integration | Funciona perfectamente con Dapper |
| Lightweight | Minimal, sin dependencias pesadas |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- DbDapperFactory.Core (>= 0.1.0)
- Microsoft.Data.Sqlite (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.1.0 | 80 | 2/18/2026 |