IAtsConvertable -- Allows custom De/Serialization across ATS boundaries#17473
Draft
cdbrown2018 wants to merge 4 commits into
Draft
IAtsConvertable -- Allows custom De/Serialization across ATS boundaries#17473cdbrown2018 wants to merge 4 commits into
cdbrown2018 wants to merge 4 commits into
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17473Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17473" |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for custom ATS conversion for “generic” objects by introducing an IAtsConvertable contract and wiring AtsMarshaller to call custom Deserialize logic, with a new test validating deserialization into a dictionary-backed DTO.
Changes:
- Introduce
IAtsConvertableandCustomAtsObjectDtoto support custom JSON ↔ object conversion across ATS boundaries. - Update
AtsMarshallerto detect ATS-convertible types and invoke their custom deserializer. - Replace an existing unmarshalling test with a new test for custom ATS object DTO deserialization.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/Aspire.Hosting.RemoteHost.Tests/AtsMarshallerTests.cs | Adds test coverage for unmarshalling into CustomAtsObjectDto (but removes a prior init-list test). |
| src/Aspire.Hosting/Ats/AtsConvertable.cs | Introduces IAtsConvertable and CustomAtsObjectDto with dictionary-based JSON conversion logic. |
| src/Aspire.Hosting.RemoteHost/Ats/AtsMarshaller.cs | Adds detection and reflection-based invocation of Deserialize for ATS-convertible types. |
Comment on lines
+659
to
+662
| if (IsIAtsConvertable(targetType)) | ||
| { | ||
| return targetType.GetMethod("Deserialize")?.Invoke(null, [jsonObj]); | ||
| } |
Comment on lines
+121
to
+124
| public static JsonNode? Serialize(object value) | ||
| { | ||
| return JsonSerializer.Serialize(value); | ||
| } |
Comment on lines
+12
to
+13
| public interface IAtsConvertable | ||
| { |
| /// Contains the result of deserialization. | ||
| /// </summary> | ||
| [AspireExportIgnore] | ||
| internal Dictionary<string, object?>? Object { get; set; } |
Comment on lines
+685
to
+688
| private static bool IsIAtsConvertable(Type type) | ||
| { | ||
| return type.GetInterfaces().Any(x => x.FullName == "Aspire.Hosting.Ats.IAtsConvertable"); | ||
| } |
Comment on lines
+717
to
+718
| [Fact] | ||
| public void UnmarshalFromJson_UnmarshalsCustomAtsObjectDto() |
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 free
to 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.
Description
Adds support for declaring custom Serialization and Deserialization logic across ATS boundaries.
Two types have been added --
IAtsConvertableandCustomAtsObjectDto.IAtsConvertableImplement this interface to provide custom de/serialization logic for a type that is exported over ATS. The Deserialize and Serialize methods are marked static as it is expected these methods will return an object of the type these methods are defined on.
IAtsConvertablewas added to the Unmarshalling logic, so anything that implements the interface will be deserialized accordingly.CustomAtsObjectDtoThis class provides a default implementation of the
IAtsConvertable. It simply takes aJsonObjectand deserializes it to aDictionary<string, object?>. The property is set to the class'sObjectproperty, to be used in SDK code. This allows completely custom objects to be sent across ATS boundaries, allowing client-code to specify their own objects. Particularly, this enables writing custom manifests for publishers, without having to make use of extension methods, and using the AppHost language's native object creation semantics.An example of how this type is used is available in the #17074 PR.
Checklist
<remarks />and<code />elements on your triple slash comments?