-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Stateful converters with hydration #16670
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
[dotnet] [bidi] Stateful converters with hydration #16670
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
|
I successfully implemented 2 variants:
Task<Result> DoSomethingAsync()
{
var result = await Broker.ExecuteCommandAsync(....);
result.Hydrate(); // walk through all nested object properties and set `BiDi` instance
return result;
}The 2nd variant is technically ideal, but it requires a lot of boilerplate code. It also introduces new rule for us. |
| new WebExtensionConverter(this), | ||
| } | ||
| }; | ||
| return (T)_modules.GetOrAdd(typeof(T), _ => Module.Create<T>(this, Broker, _jsonOptions)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still support adding a module after BiDi is created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, each module creates new copy of provided instance.
var logOptions = new JsonSerializerOptions(jsonSerializerOptions)
{
Converters =
{
new BrowsingContextConverter(BiDi),
new RealmConverter(BiDi),
new InternalIdConverter(BiDi),
new HandleConverter(BiDi),
}
};
_jsonContext = new LogJsonSerializerContext(logOptions);We can simplify it, and always put new instance into module Initialize(...). I would be better for external modules. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

User description
Finally resolving issues with BiDi AOT trimming.
🔗 Related Issues
Related to #16095
💥 What does this PR do?
🔧 Implementation Notes
BiDiinstance in DTO ctor💡 Additional Considerations
Now assembly is fully trimmable, as we wanted.
🔄 Types of changes
PR Type
Bug fix, Enhancement
Description
Removes stateful JSON converters to enable AOT trimming
Implements hydration pattern for BiDi property injection
Converts JsonSerializerContext to static singletons
Adds IBiDiHydratable interface for post-deserialization setup
Diagram Walkthrough
File Walkthrough
20 files
New interface for post-deserialization hydrationHydrate command results and event argsImplement IBiDiHydratable for event argsConvert context to static singleton with attributesImplement IBiDiHydratable for resultConvert context to static singleton with attributesImplement IBiDiHydratable for resultImplement IBiDiHydratable for tree resultImplement IBiDiHydratable for resultImplement IBiDiHydratable for resultConvert context to static singleton with attributesImplement IBiDiHydratable for resultConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributesConvert context to static singleton with attributes20 files
Remove JsonOptions from module creationRemove Initialize method and JsonOptions parameterRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove BiDi constructor parameter, add hydrationRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove stateful BiDi instance from converterRemove BiDi constructor parameter, add hydration