✨Add UnitsNetSetup to hold global static state - #1267
Merged
Conversation
angularsen
marked this pull request as ready for review
June 18, 2023 22:18
angularsen
enabled auto-merge (squash)
June 18, 2023 22:19
angularsenforce-pushed
the
agl/unitsnetsetup
branch
from
July 10, 2023 22:01
f540d8d to
5629accCompareFix static init racing condition by replacing {get;} with =>Move unit abbreviations out of UnitInfo and into UnitAbbreviationsCache, so manipulating one cache instance won't affect another instance.
angularsenforce-pushed
the
agl/unitsnetsetup
branch
from
July 11, 2023 00:17
34d4193 to
a93fc31Compare
This was referenced Jul 11, 2023
angularsen
commented
Jul 11, 2023
OwnerAuthor
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 freeto 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.
Added
UnitsNetSetupto gather global state in a single place as a singleton, with the possibility of passing instances of it to static methods later to override the defaults.This way, state is no longer scattered among multiple classes that depend on each other in non-obvious ways and where initialization order has caused issues up until now.
Changes
UnitsNetSetupto hold global state as a singleton propertyDefaultthat controls default state initialization.UnitConverter, UnitAbbreviationsCache, UnitParser, QuantityParserDefaultsingleton properties from these services toUnitsNetSetup.Defaultand mark obsoleteTesting
❌ Still running into a handful of flaky tests due to racing conditions.
This was a regression in #1210, but still not fixed.
Will investigate and fix in separate PR.