Fix: Unity RegisterComponent with Keyed Throws Exception#842
Open
Selakz wants to merge 1 commit intohadashiA:masterfrom
Open
Fix: Unity RegisterComponent with Keyed Throws Exception#842Selakz wants to merge 1 commit intohadashiA:masterfrom
Selakz wants to merge 1 commit intohadashiA:masterfrom
Conversation
|
@Selakz is attempting to deploy a commit to the hadashia's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request is related to issue #794.
The Problem:
In the current implementation of
RegisterComponentandRegisterComponentInHierarchy, a build callback is registered to force injection by callingcontainer.Resolve(). However, it ignores the key that might be subsequently configured via.Keyed(key). This leads to aVContainerExceptionduring the build phase because the container tries to resolve a default (unkeyed) registration that doesn't exist. Also, the keyed registration will not be force injected.Though the main purpose of
RegisterComponentis to trigger auto-injection, since it returns aRegistrationBuilder, I believe ensuring it respects the key parameter is important for internal state consistency.The Solution:
Passed
registrationBuilder.Keyinto theResolvemethod within the build callback. Since the default value of thekeyparameter inResolveis null, I think this change is backward compatible and correctly handles both keyed and non-keyed registrations.