feat: add healthcheck for databases

This commit is contained in:
2024-10-25 02:35:36 +03:00
parent 428c2dc3ba
commit 98ee3c389c
2 changed files with 18 additions and 3 deletions

View File

@ -86,4 +86,15 @@ public static class DependencyInjection
};
}
}
public static IHealthChecksBuilder AddDatabaseHealthCheck(this IHealthChecksBuilder healthChecksBuilder, DatabaseProvider dbProvider, string connection)
{
return dbProvider switch
{
DatabaseProvider.Mysql => healthChecksBuilder.AddMySql(connection, name: "MySql"),
DatabaseProvider.Sqlite => healthChecksBuilder.AddSqlite(connection, name: "Sqlite"),
DatabaseProvider.Postgresql => healthChecksBuilder.AddNpgSql(connection, name: "PostgreSQL"),
_ => throw new ArgumentException("Unsupported database provider", Enum.GetName(dbProvider))
};
}
}