Refactor ATS Code Generation and Context Management#13869
Merged
Conversation
- Removed several classes related to reflection-only parameter and property information (RoParameterInfo, RoPropertyInfo, RoSubstitutedMethod, RoType, WellKnownTypes) to streamline the codebase. - Introduced AtsContextFactory for creating shared AtsContext from loaded assemblies. - Added CodeGenerationService to handle JSON-RPC requests for generating SDK code. - Implemented CodeGeneratorDiscovery to discover and register ICodeGenerator implementations from loaded assemblies. - Updated JsonRpcServer to include CodeGenerationService for handling code generation requests. - Enhanced RemoteHostServer to configure services for ATS context and code generation. - Made several internal classes public to allow for better accessibility in the code generation process. - Introduced ICodeGenerator interface for generating language-specific SDK code from ATS capabilities. feat: Remove obsolete project reference from solution file Implement logging and assembly loading improvements in RemoteHost - Added a new AssemblyLoader service for on-demand assembly loading with logging. - Enhanced CapabilityDispatcher to utilize ILogger for better diagnostics. - Refactored AtsContextFactory to support lazy loading of AtsContext with logging. - Introduced CodeGeneratorResolver to discover code generators from loaded assemblies. - Replaced Console.WriteLine with ILogger in various components for consistent logging. - Created RemoteAppHostService to encapsulate JSON-RPC methods and capabilities. - Updated JsonRpcServer to use dependency injection for services and improved logging. - Implemented OrphanDetector as a hosted service to monitor parent process status. - Removed CodeGeneratorDiscovery in favor of the new CodeGeneratorResolver. - Improved error handling and logging throughout the codebase.
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13869Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13869" |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the ATS (Aspire Type System) code generation architecture by:
- Removing the separate Aspire.Hosting.CodeGeneration project and consolidating code generation logic into the RemoteHost
- Making several internal ATS classes public to support external code generators (ICodeGenerator, AtsContext, AtsTypeRef, etc.)
- Introducing dependency injection for RemoteHost services with proper logging
- Changing from in-process to RPC-based code generation where the CLI calls a
generateCodeJSON-RPC method on the RemoteHost server - Deleting reflection-only type system (RoType, RoMethod, RoParameterInfo, etc.) in favor of runtime reflection via the shared RuntimeAssemblyInfo
- Converting to hosted services pattern with BackgroundService and IHostApplicationLifetime
Changes:
- Removed ~3000 lines of reflection-only code and replaced with runtime reflection via shared ATS scanning infrastructure
- Introduced 5 new services in RemoteHost: AssemblyLoader, AtsContextFactory, CodeGeneratorResolver, CodeGenerationService, RemoteAppHostService
- Changed CLI to connect via RPC to generate code instead of generating locally
- Made AtsTypeScriptCodeGenerator public and added it as a dependency to AppHostServerProject
- Added proper logging throughout with ILogger instead of Console.WriteLine
Reviewed changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting/Ats/*.cs | Made internal ATS classes public for external code generator consumption |
| src/Aspire.Hosting/Aspire.Hosting.csproj | Added InternalsVisibleTo for TypeScript code generator |
| src/Aspire.Hosting.RemoteHost/RemoteHostServer.cs | Refactored to use DI with hosted services pattern |
| src/Aspire.Hosting.RemoteHost/RemoteAppHostService.cs | New service encapsulating JSON-RPC methods |
| src/Aspire.Hosting.RemoteHost/OrphanDetector.cs | Converted to BackgroundService with ILogger |
| src/Aspire.Hosting.RemoteHost/JsonRpcServer.cs | Converted to BackgroundService with DI |
| src/Aspire.Hosting.RemoteHost/CodeGeneration/*.cs | New services for code generation via RPC |
| src/Aspire.Hosting.RemoteHost/AssemblyLoader.cs | New service for lazy assembly loading |
| src/Aspire.Hosting.CodeGeneration/**/*.cs | Deleted entire project (~3000 lines) |
| src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs | Made public, added disconnect handler |
| src/Aspire.Hosting.CodeGeneration.TypeScript/*.csproj | Changed to reference Aspire.Hosting instead of CodeGeneration |
| src/Aspire.Cli/Projects/TypeScriptAppHostProject.cs | Refactored to use RPC for code generation |
| src/Aspire.Cli/Projects/AppHostServerProject.cs | Added TypeScript code generator to dependencies |
| src/Aspire.Cli/Aspire.Cli.csproj | Removed direct code generation project references |
| playground/TypeScriptAppHost/.modules/aspire.ts | Generated code with API changes |
| Aspire.slnx | Removed CodeGeneration project from solution |
…tionality - Introduced cancellation token registry to manage cancellation requests. - Added `registerCancellation` and `unregisterCancellation` functions for handling AbortSignal. - Enhanced `AspireClient` with a `cancelToken` method to send cancellation requests. - Updated tests to verify cancellation token functionality and integration with existing capabilities. - Refactored related classes and methods to accommodate cancellation token parameters.
- Removed the IAtsReflection interfaces and their implementations (RuntimeReflectionWrappers.cs) to streamline the ATS scanning process. - Updated AtsTypeScriptCodeGeneratorTests to reflect changes in method naming conventions, replacing MethodName with QualifiedMethodName. - Simplified capability scanning in tests by removing unnecessary wrapping of assemblies with RuntimeAssemblyInfo. - Enhanced test snapshots to include ClrType for parameters and return types for better type mapping. - Adjusted AtsCapabilityScannerTests to directly use Type instead of RuntimeTypeInfo for type ID mapping, improving test clarity and performance.
- Updated multiple test files to replace direct HandleRegistry usage with AtsMarshaller for better context management. - Introduced CreateTestMarshaller and CreateTestMarshallerWithCallbacks methods to streamline marshaller creation in tests. - Removed AtsIntrinsicsTests.cs as it was deemed unnecessary. - Enhanced existing tests to ensure compatibility with new marshaller structure and improved error handling. - Added IsResourceBuilder property to various DTOs in snapshots to reflect updated capabilities.
- Updated TypeScript snapshots to include new properties: IsDistributedApplicationBuilder and IsDistributedApplication. - Modified AtsContext initialization in multiple test files to replace TypeInfos with HandleTypes for consistency across tests.
…he TypeScriptAppHost dist directory to streamline the project structure and eliminate unused code.
…eter in MapToAtsTypeId method calls
3 tasks
sebastienros
approved these changes
Jan 13, 2026
… IInteractionService directly, simplifying dependency injection in tests
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Refactor Polyglot AppHost Infrastructure
Follow up to #13705
Summary
This PR simplifies and consolidates the polyglot app host infrastructure by removing unnecessary abstraction layers and improving the developer experience for TypeScript/Python app hosts.
What Changed
Removed
Aspire.Hosting.CodeGenerationproject - The complex metadata-only reflection system was replaced with direct runtime reflection, significantly reducing code complexity (~5000 lines removed)Improved TypeScript SDK generation - Fixed issues where DTO types were incorrectly treated as handle types, and added cancellation token support
Better dev mode experience - The CLI now reads DCP version from the repo when
ASPIRE_REPO_ROOTis set, and generated files are properly gitignoredCleaner type system naming - Renamed internal APIs to better reflect the three distinct type categories: Handle Types (passed by reference), DTO Types (serialized as JSON), and Enum Types
Test Plan