SafeConnection 1.0.1
See the version list below for details.
dotnet add package SafeConnection --version 1.0.1
NuGet\Install-Package SafeConnection -Version 1.0.1
<PackageReference Include="SafeConnection" Version="1.0.1" />
<PackageVersion Include="SafeConnection" Version="1.0.1" />
<PackageReference Include="SafeConnection" />
paket add SafeConnection --version 1.0.1
#r "nuget: SafeConnection, 1.0.1"
#:package SafeConnection@1.0.1
#addin nuget:?package=SafeConnection&version=1.0.1
#tool nuget:?package=SafeConnection&version=1.0.1
SafeConnection is a robust library designed to facilitate secure and efficient database connections.
It provides a comprehensive set of features including:
- **Secure Connections**: Ensures all database connections are secure and encrypted. Additionally it closes the passed connection explicitly.
- **Caching**: Implements in-memory caching to reduce database load and improve performance.
- **Logging**: Integrated logging capabilities to track database operations and errors.
- **Compatibility**: Supports multiple .NET versions including .NET Standard 3.1 and .NET 6.0.
- **Ease of Use**: Simple and intuitive API for quick integration into your projects.
This library is ideal for applications that require reliable and secure database interactions with minimal overhead.
### Usage Instructions
To use SafeConnection, simply install the package via NuGet and add the following code to your project:
1. **Install the Package**:
Add the SafeConnection package to your project using NuGet:
```bash
dotnet add package SafeConnection
```
2. **Inject the Service**:
Inject the SafeConnection service into your application as Singleton:
```csharp
builder.Services.AddSingleton<SafeConnection>(_ => new SafeConnection(
appName: builder.Environment.ApplicationName, // It will be used in the logs.
environment: builder.Environment.EnvironmentName, // It will be used in the logs.
sqlConnectionString: builder.Configuration.GetConnectionString("Your_Sql_log_connectionString"), // Where the logs will be stored.
sqlTable: "App_Logs", // The table where the logs will be stored.
cacheExpirationMinutes: builder.Configuration.GetValue<int>("CacheExpirationInMinutes") // The expiration time of the cache in minutes.
));
```
3. **Use the Service**:
Use the SafeConnection service in your application to interact with the database:
```csharp
public class YourService
{
private readonly SafeConnection _safeConnection;
// Inject SafeConnection service
public YourService(SafeConnection safeConnection)
{
_safeConnection = safeConnection;
}
// Use SafeConnection to execute SQL queries
public async Task<IEnumerable<YourModel>> GetYourData()
{
return await _safeConnection.QueryAsync<YourModel>("SELECT field1, field2 FROM YourTable", "YourCacheKey");
}
}
```
4. **The sql table structure**:
```sql
CREATE TABLE App_Logs (
Id int IDENTITY(1,1) NOT NULL,
[DateTime] datetime NOT NULL,
App varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Env varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Query varchar(500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Cached bit NOT NULL,
Duration real NOT NULL,
[Rows] int NOT NULL,
Columns int NOT NULL,
Kb int NULL,
CONSTRAINT App_Logs_PK PRIMARY KEY (Id)
);
```
5. **Enjoy!**
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Dapper (>= 2.0.90)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Microsoft.Extensions.Caching.Abstractions (>= 3.1.18)
- Microsoft.Extensions.Caching.Memory (>= 3.1.18)
-
net6.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Microsoft.Extensions.Caching.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Caching.Memory (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.