20 lines
510 B
C#
20 lines
510 B
C#
using System.Data;
|
|
using Npgsql;
|
|
using ScrapperAPI.Interfaces;
|
|
|
|
namespace ScrapperAPI.Factories;
|
|
|
|
public sealed class NpgsqlConnectionFactory : IDbConnectionFactory
|
|
{
|
|
private readonly string _cs;
|
|
|
|
public NpgsqlConnectionFactory(IConfiguration cfg)
|
|
=> _cs = cfg.GetConnectionString("Default")!;
|
|
|
|
public async Task<IDbConnection> CreateOpenConnectionAsync(CancellationToken ct)
|
|
{
|
|
var conn = new NpgsqlConnection(_cs);
|
|
await conn.OpenAsync(ct);
|
|
return conn;
|
|
}
|
|
} |