I have a function that gets the statues of my databases and Redis instances to check that they are online:
internal static bool IsOnline(ConnectionLocator connectionLocator)
{
try
{
connectionLocator.SessionDatabase.Ping(StackExchange.Redis.CommandFlags.None);
using (var connect = connectionLocator.OpenSqlConnection())
{
var command = connect.CreateCommand();
command.CommandText = "select 1";
command.ExecuteScalar();
}
}
}
catch
{
return false;
}
return true;
}
This is used to display a system status to the consumers of my application.
Currently, I have it in the MVC controller it is called from, but I don't think that is quite right.
However, it doesn't seem appropriate to put this in a repository either; I am asking about data access, NOT trying to abstract the data access details away from an entity.
Is anyone aware of patterns, or best case practices for this kind of systems interrogation code?