Library for inspect database connections and prevent requests to its until establish conneciton (for Asp.Net apps)
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
Here the example of how you can use this library in your Asp.Net project (from Example project)
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());
}
In this case checking will be always succeed whether inspection is required or not
app.UseDbConnectionInspector(new ConnectionOptions());
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);
- Embedding inspector to request pipeline
- Support PostgreSQL
- 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
Architecture has been redesigned, so a new version is not compatible with old one
- Attribute based inspection
Starting with this version connection inspection would be called only for controller methods marked by special attributeRequireDbInspection
- Added additional parameter for
IConnectionChecker
-key
for identification each checker - Added ability provide
key
parameter inRequireDbInspection
attribute constructor - Change inspection logic