[dotnet] [bidi] Stateful converters with hydration#16670
[dotnet] [bidi] Stateful converters with hydration#16670nvborisenko merged 33 commits intoSeleniumHQ:trunkfrom
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.
Does this still support adding a module after BiDi is created?
There was a problem hiding this comment.
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.

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