-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Stateless 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
base: trunk
Are you sure you want to change the base?
[dotnet] [bidi] Stateless 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:
|
|||||||||||||||
| [JsonSerializable(typeof(SetDownloadBehaviorCommand))] | ||
| [JsonSerializable(typeof(SetDownloadBehaviorResult))] | ||
|
|
||
| #pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant |
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.
Better [ClsCompliant(false)] I think. You’ll probably run into dotnet/roslyn#68560 though.
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.
We are CLS compliant:
| [assembly: System.CLSCompliant(true)] |
| var commandResult = JsonSerializer.Deserialize(ref resultReader, command.JsonResultTypeInfo) | ||
| ?? throw new JsonException("Remote end returned null command result in the 'result' property."); | ||
|
|
||
| if (commandResult is IBiDiHydratable bidiHydratable) |
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.
Do we have any types with properties that are BiDi hydratable? We might need to handle nested structures.
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.
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.
I hydrated couple just to make tests green. If we like the approach, I will review all top-level CommndResults/EventArgs to include nested properties.
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:
|
||||||||||||
|
|
||
| #pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNameCaseInsensitive = true, |
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.
We are duplicating shared json options. Is it good? Or do we want to return back the construction of json context in runtime rather than generated options?
|
|
||
| // BiDi returns special numbers such as "NaN" as strings | ||
| // Additionally, -0 is returned as a string "-0" | ||
| NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals | JsonNumberHandling.AllowReadingFromString, |
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.
Is it safe to remove runtime options completely? As I remember we implemented it as converter?..
| public sealed class BrowserModule : Module | ||
| { | ||
| private BrowserJsonSerializerContext _jsonContext = null!; | ||
| private static readonly BrowserJsonSerializerContext _jsonContext = BrowserJsonSerializerContext.Default; |
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.
If we choose generated options, then rename -> s_jsonContext
|
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. |
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