While adding Service Bus emulator support for Aspire (https://github.com/dotnet/aspire/pull/6737) I faced the issue to have to create health checks on the configured queues and topics, but not be able to conditionally add these health checks.
What happens is that we can correctly pass a lambda in the health checks registrations to provide the name of a queue or a topic, but if there are no queues or no topics then we have registered a health check and nothing to provide. The same way we can't provide multiple health checks (several queues or several topics).
How I solved it is by creating a custom health check that accepts a factory for a list of queues/topics instead. Technically the only difference would be that the current factories would return a list of values, potentially empty, instead of exactly one value which can't be null.
While adding Service Bus emulator support for Aspire (https://github.com/dotnet/aspire/pull/6737) I faced the issue to have to create health checks on the configured queues and topics, but not be able to conditionally add these health checks.
What happens is that we can correctly pass a lambda in the health checks registrations to provide the name of a queue or a topic, but if there are no queues or no topics then we have registered a health check and nothing to provide. The same way we can't provide multiple health checks (several queues or several topics).
How I solved it is by creating a custom health check that accepts a factory for a list of queues/topics instead. Technically the only difference would be that the current factories would return a list of values, potentially empty, instead of exactly one value which can't be null.