Refactor: Separate AutoInject from SetContainer build callback - #856
Refactor: Separate AutoInject from SetContainer build callback#856asdqwe02 wants to merge 1 commit into
Conversation
|
@asdqwe02 is attempting to deploy a commit to the hadashia's projects Team on Vercel. A member of the Team first needs to authorize it. |
…ll order - change SetContainer build callback to the start of container build configuration - separate AutoInjectAll method from SetContainer and set AutoInjectAll as the last container built callback
|
@hadashiA hey sorry for the tag but if possible can you check this pull request? I understand it sound like a minor issue but I think updating it could help other who have issues with container built callback being called after AutoInject is run |
|
Hi, thanks for the PR. First, this is a minor point, but regarding the PR title. This isn't a refactoring. It is a fix accompanied by breaking changes with the intent that "I want to execute AutoInjectAll only after all user-defined build callbacks are completed." Since it also affects existing users, I'd like you to state that clearly in the title and description. While I think this request makes sense, there seem to be the following issues with the implementation:
In the current implementation, AutoInjectAll is always first, so it was guaranteed that "auto-injection is complete when the entry point executes." This PR is a regression that loses that guarantee (when entry points are registered inside Configure). Presumably, a different mechanism to guarantee the order is needed. |
RegisterBuildCallback(SetContainer)to start ofInstallTo.AutoInjectAllfromSetContainerand add to container build callback at the end ofInstallToCurrently,
SetContaineris registered as a build callback beforeInstallTois called andAutoInjectAllis call insideSetContainer, meaning user-defined container build callbacks will be called after MonoBehaviours are auto-injected via LifetimeScope.This change separate
AutoInjectAllfromSetContainerand addbuilder.RegisterBuildCallback(AutoInjectAll)to the end ofInstallTo, ensuring it is always the last registered build callback. As a result, when MonoBehaviours are auto-injected via LifetimeScope, all container build callbacks (including any registered by user installers) are guaranteed to have completed first.Before:
SetContainer(withAutoInjectAll) callback was registered before InstallTo, so it could be invoked before user-defined callbacks.After:
AutoInjectAllis separated fromSetContainer, addAutoInjectAllas last container build callback so it runs after all other build callbacks have finished.