Alias health
in lieu of a separate binding
#129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey 👋
This PR addresses an issue that arises when using Laravel's Container Events.
Given the following excerpt from an actual
ServiceProvider
:Triggering the
health:schedule-check-heartbeat
command makes the application crash with the following exception:Spatie\Health\Exceptions\DuplicateCheckNamesFound
Digging a bit deeper reveals that the command eventually makes use of the
Health
Facade on L17.The problem with this, is that the
Facade
makes use of thehealth
binding instead of the singletonHealth::class
binding. A kinda hidden and notorious behaviour of theFacade
class is that it creates a completely separate service context, ie. non-singleton bindings will be treated as singletons when making use of aFacade
.TL;DR By aliasing
health
toHealth
, we can ensure the same instance is used across all possible use cases.(I have also removed the
Closure
defined on L39 because the IoC container will be able to auto-wire that without any problems.)Thanks!