iCat.DB.Client.Extension.Web
1.1.5
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package iCat.DB.Client.Extension.Web --version 1.1.5
NuGet\Install-Package iCat.DB.Client.Extension.Web -Version 1.1.5
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="iCat.DB.Client.Extension.Web" Version="1.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add iCat.DB.Client.Extension.Web --version 1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: iCat.DB.Client.Extension.Web, 1.1.5"
#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.
// Install iCat.DB.Client.Extension.Web as a Cake Addin
#addin nuget:?package=iCat.DB.Client.Extension.Web&version=1.1.5
// Install iCat.DB.Client.Extension.Web as a Cake Tool
#tool nuget:?package=iCat.DB.Client.Extension.Web&version=1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
iCat.DB.CLient
iCat.DB.Client is a UnitOfWork design pattern library for db connection. It can manages and serves dynamic provide db clients at runtime.
Description
The library provides two way for registering IUnitOfWork and IConnection. IUnitOfWork and IConnection export the DBConnection property, which can also used in dapper.net.
- General fixed connection registration, registered when the application started, can't be modified.
- Through factory registration, programers can implement "IDBClientProvider" to provide IUnitOfWork/IConnection,
As a reminder, the IUnitOfWork/IConnection obtained from "General Fixed Connection Registration" and "Factory" are different instances.
Installation
dotnet add package iCat.DB.Client
dotnet add package iCat.DB.Client.Extension.Web
dotnet add package iCat.DB.Client.Factory
Sample ( Single database )
Program.cs
using iCat.DB.Client.Extension.Web;
using iCat.DB.Client.Implements;
using iCat.DB.Client.Models;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
services.AddDBClient((s) => new DBClient(new SqlConnection("Your connection string")));
services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapControllers();
app.Run();
}
}
Controller
using iCat.DB.Client.Interfaces;
[ApiController]
[Route("[controller]")]
public class DemoController : ControllerBase
{
private readonly IUnitOfWork _unitOfWork;
private readonly IConnection _connection;
public DemoController(IUnitOfWork unitOfWork, IConnection connection)
{
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
_connection = connection ?? throw new ArgumentNullException(nameof(connection));
}
[HttpGet]
public IActionResult Get()
{
using (_unitOfWork)
{
try
{
_unitOfWork.Open();
_unitOfWork.BeginTransaction();
foreach (var dr in _connection.ExecuteReader("SELECT * FROM YourTable", new DbParameter[] { }))
{
var filed = dr["fieldName"];
};
_unitOfWork.Commit();
}
catch (Exception)
{
_unitOfWork.Rollback();
}
finally
{
_unitOfWork.Close();
}
}
return Ok();
}
}
Sample ( General Fixed Connections Registration )
Program.cs
using iCat.DB.Client.Extension.Web;
using iCat.DB.Client.Implements;
using iCat.DB.Client.Models;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
services
.AddDBClients(
(s) => new DBClient(new DBClientInfo("MainDB", new SqlConnection("Your connection string"))),
(s) => new DBClient(new DBClientInfo("Company", new SqlConnection("Your connection string")))
);
services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapControllers();
app.Run();
}
}
Controller
using iCat.DB.Client.Interfaces;
[ApiController]
[Route("[controller]")]
public class DemoController : ControllerBase
{
private readonly IEnumerable<IUnitOfWork> _unitOfWorks;
private readonly IEnumerable<IConnection> _connections;
public DemoController(IEnumerable<IUnitOfWork> unitOfWorks, IEnumerable<IConnection> connections)
{
_unitOfWorks = unitOfWorks ?? throw new ArgumentNullException(nameof(unitOfWorks));
_connections = connections ?? throw new ArgumentNullException(nameof(connections));
}
[HttpGet]
public IActionResult Get()
{
using (var unitOfWork = _unitOfWorks.First(p => p.Category == "MainDB"))
{
try
{
unitOfWork.Open();
unitOfWork.BeginTransaction();
var connection = _connections.First(p => p.Category == "MainDB");
foreach (var dr in connection.ExecuteReader("SELECT * FROM YourTable", new DbParameter[] { }))
{
var filed = dr["fieldName"];
};
unitOfWork.Commit();
}
catch (Exception)
{
unitOfWork.Rollback();
}
finally
{
unitOfWork.Close();
}
}
return Ok();
}
}
Sample ( Through factory registration )
Program.cs
using iCat.DB.Client.Extension.Web;
using iCat.DB.Client.Implements;
using iCat.DB.Client.Models;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
services
.AddDBClientFactory(
() => new DBClient(new DBClientInfo("MainDB", new SqlConnection("Your connection string"))),
() => new DBClient(new DBClientInfo("Company", new SqlConnection("Your connection string")))
);
services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapControllers();
app.Run();
}
}
Controller
using iCat.DB.Client.Factory.Interfaces;
[ApiController]
[Route("[controller]")]
public class DemoController : ControllerBase
{
private readonly IDBClientFactory _factory;
public DemoController(IDBClientFactory factory)
{
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
}
[HttpGet]
public IActionResult Get()
{
using (var unitOfWork = _factory.GetUnitOfWork("MainDB"))
{
try
{
unitOfWork.Open();
unitOfWork.BeginTransaction();
var connection = _factory.GetConnection("MainDB");
foreach (var dr in connection.ExecuteReader("SELECT * FROM YourTable", new DbParameter[] { }))
{
var filed = dr["fieldName"];
};
unitOfWork.Commit();
}
catch (Exception)
{
unitOfWork.Rollback();
}
finally
{
unitOfWork.Close();
}
}
return Ok();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- iCat.DB.Client.Factory (>= 2.0.2)
-
net7.0
- iCat.DB.Client.Factory (>= 2.0.2)
-
net8.0
- iCat.DB.Client.Factory (>= 2.0.2)
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.3.5-alpha | 50 | 5/20/2024 | |
1.1.5 | 131 | 1/20/2024 | |
1.1.4 | 140 | 1/3/2024 | |
1.0.3 | 89 | 1/2/2024 | |
1.0.2 | 123 | 12/31/2023 |
Version 1.1.5