FP.DbConnectionFactory 1.2.0

dotnet add package FP.DbConnectionFactory --version 1.2.0
                    
NuGet\Install-Package FP.DbConnectionFactory -Version 1.2.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="FP.DbConnectionFactory" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FP.DbConnectionFactory" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="FP.DbConnectionFactory" />
                    
Project file
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 FP.DbConnectionFactory --version 1.2.0
                    
#r "nuget: FP.DbConnectionFactory, 1.2.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 FP.DbConnectionFactory@1.2.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=FP.DbConnectionFactory&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=FP.DbConnectionFactory&version=1.2.0
                    
Install as a Cake Tool

DbConnectionFactory - a way to connect with differents databases

Creation of different database connections using the factory pattern. This package was created to work primarily with dapper ORM and is currently only available for .NET Core 7.0.

Package

DbConnectionFactory is a NuGet library
Source code: GitHub
You can also use docfx as a NuGet library:

<PackageReference Include="FP.DbConnectionFactory" Version="1.2.0" />

Example usage:


public class Employee
{
    private readonly IConfiguration _configuration;
    private readonly IDbFactory _factory;
    
    public Employee(IConfiguration configuration, IDbFactory factory)
    {
        _configuration = configuration;
        _factory = factory;
    }

    private IDbConnection connection() => _factory.CreateConnection(ServerType.PostgreSQL, _configuration).GetConnection();

    public async Task<int> AddAsync(Entity entity)
    {
         var sql = "Insert/Select/Delete/Update";
         var result = await connection().ExecuteAsync(sql, entity);
         connection().Close();
         return result;
    }
}
  //Program.cs
  services.AddScoped<IDbFactory, DbFactory>();
Examples of connection strings

The following are examples for some databases

Postgres

  • Server=ip;Port=5432;Database=database;User Id=postgres;Password=password;

MySql and MariaDb

  • Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

SQL Server

  • Server=mySQLServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
 "ConnectionStrings": {
    "DefaultConnection": "connectionString"
  }

Note: Please feel free to educate me if you have any comments.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.

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
1.2.0 179 7/11/2023
1.1.0 150 6/24/2023
1.0.3 143 6/23/2023
1.0.2 146 6/23/2023
1.0.1 145 6/23/2023
1.0.0 138 6/23/2023