DatabaseConnectionInspector 3.1.0

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

Connection Inspector

Library for inspect database connections and prevent requests to its until establish conneciton (for Asp.Net apps)

Library Purpose

Library purpose is to try to help achieve max app reliability by handling database connection state. That is if your database server was down app would continue it's work

How to use library

Here the example of how you can use this library in your Asp.Net project (from Example project)

Common use

In your Program.cs or Startup.cs file:

app.UseDbConnectionInspector(new ConnectionOptions()
{
    new ConnectionChecker(new NpgsqlConnection(connString)),
    new ConnectionChecker(new MySqlConnection(connString))
});

You can provide key parameter

app.UseDbConnectionInspector(new ConnectionOptions()
{
    new ConnectionChecker(new NpgsqlConnection(connString), "chekerOne"),
    new ConnectionChecker(new MySqlConnection(connString), "checkerTwo")
});

In your controller:

[RequireDbInspection]
[HttpGet("/get")]
public IActionResult Get()
{
    return Ok(_dbContext.Models.ToList());
}

If you want check only one specific connection:

[RequireDbInspection("checkerKey")]
[HttpGet("/get")]
public IActionResult Get()
{
    return Ok(_dbContext.Models.ToList());
}

Without connections

In this case checking will be always succeed whether inspection is required or not

app.UseDbConnectionInspector(new ConnectionOptions());

Specify action

You may specify what action would be invoked if connection failed

app.UseDbConnectionInspector(new ConnectionOptions()
{
    new ConnectionChecker(new NpgsqlConnection(connString))
}, context => context.Response.StatusCode = (int)HttpStatusCode.BadRequest);

Features list v1.0

  • Embedding inspector to request pipeline
  • Support PostgreSQL

Features list v2.0

  • Specify action that would be invoke if connection failed
  • Support for all connection providers who provide a class that implements IDbConnection interface
  • Logger for inspector

Note

Architecture has been redesigned, so a new version is not compatible with old one

Features list v3.0

  • Attribute based inspection
    Starting with this version connection inspection would be called only for controller methods marked by special attribute RequireDbInspection

Features list v3.0.1

  • Added additional parameter for IConnectionChecker - key for identification each checker
  • Added ability provide key parameter in RequireDbInspection attribute constructor
  • Change inspection logic
Product 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 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. 
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
3.1.0 474 10/20/2022
3.0.0 396 10/17/2022
2.0.0 429 10/15/2022
1.0.1 427 10/13/2022
1.0.0 415 10/13/2022