Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make injection order predictable #402

Merged
merged 3 commits into from
Nov 6, 2022

Conversation

Pablete1234
Copy link
Contributor

Very simple change that makes it so the order injectors are called in is the one they were registered in, instead of being arbitrary.

This is relevant when the injectors overlap on classes, eg: CommandSender vs Player injectors, if your command wants to be injected a "CommandSender", it could randomly first attempt the player one (as player is compatible) and if player isn't available (eg: console) then it would go to the other injector for the actual CommandSender.

While this is probably a minor change it otherwise becomes impossible to make required injectors that will throw exceptions (later handled by the exception handler) when the necessary context isn't available when classes overlap. In the previous example, if the injector for Player threw an exception when the caller isn't a player, then randomly no command would be able to run from console (if you're unlucky enough that the player injector is called first).

With this change, as long as you register CommandSender's injector first, and then Player, such behavior works reliably.

@jpenilla jpenilla changed the base branch from master to 1.8.0-dev November 6, 2022 18:29
@jpenilla jpenilla merged commit 4e0bb9a into Incendo:1.8.0-dev Nov 6, 2022
@zml2008 zml2008 added this to the 1.8.0 milestone Dec 9, 2022
jpenilla pushed a commit that referenced this pull request Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants