-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ParameterState: Add scope registration, lock mechanism, ComponentBaseWithState #8683
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #8683 +/- ##
==========================================
+ Coverage 89.82% 90.11% +0.28%
==========================================
Files 412 418 +6
Lines 11878 12046 +168
Branches 2364 2365 +1
==========================================
+ Hits 10670 10855 +185
+ Misses 681 658 -23
- Partials 527 533 +6 ☔ View full report in Codecov by Sentry. |
@henon I can finally say that I really love the current registration mechanism, knowing that everything is now locked, truly readonly and that there is no voodoo magic when the |
Added |
Awesome! Nice work. Can we rename It makes the code even more intuitive to read, it s almost like English: After: using var registerScope = CreateRegisterScope();
_valueState = registerScope.RegisterParameter<double>(nameof(Value))
.WithParameter(() => Value)
.WithChangeHandler(OnParameterChangedShared)
.WithComparer(DoubleEpsilonEqualityComparer.Default); And I think we should remove |
is it fine to make |
No problem, internal is good. |
Description
New syntax to register parameters:
You are not allowed to create more than one scope.
This is necessary for code simplicity:
Attach
method.ParameterSet
is now readonly allowing to useFrozenDictionary
(net8).The idea is very simple.
The
RegisterParameterBuilder<T>
is now caching theParameterStateInternal<T>
and every-time theAttach
method is called, it returns the same instance.The backing-fields getting the instance of
ParameterState
through thatAttach
, and later on all theParameterState
s will be collected again through theAttach
, this is why returning same instance is important.For the cache we use
Lazy
, because it's is very cheap, thread safe and the code is very simple, you don't have to worry about many things.ParameterRegistrationBuilderScope
is stashing all the builders (RegisterParameterBuilder<T>
), when the scope ends (Dispose
) theParamterSet
will collect all theParameterStateInternal
by reading a lazy-collectionIEnumerable<IParameterComponentLifeCycle>
.ParamterSet
is also creating the dictionary lazily.Therefore any kind of reading in the
ParameterSet
will initiate the parameters reading (aka initialize the dictionary, so it's auto-locked on first read).How Has This Been Tested?
New tests, current tests, visually
Types of changes
Checklist
dev
).