Skip to content

Add comprehensive annotations documentation for .NET Aspire #4059

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 15, 2025

This PR adds comprehensive documentation for annotations in .NET Aspire, addressing a significant gap in the documentation where annotations are used extensively across the stack but lacked centralized coverage.

What's Added

📄 New Documentation: docs/fundamentals/annotations-overview.md

  • What are annotations: Complete explanation of the annotation system and IResourceAnnotation interface
  • Built-in annotation types: Coverage of key annotations like EndpointAnnotation, ResourceUrlAnnotation, EnvironmentCallbackAnnotation, ContainerMountAnnotation, and CommandAnnotation
  • Creating custom annotations: Step-by-step guide with working examples
  • Advanced patterns: Conditional annotations, composition, validation, and testing approaches
  • Best practices: Guidelines for naming, documentation, and maintaining focused responsibilities

💻 Working Code Examples: docs/fundamentals/snippets/annotations-overview/

All code examples are fully compilable and demonstrate:

  • Custom annotation implementation patterns
  • Extension method patterns following .NET Aspire conventions
  • Annotation processing and inspection techniques

🗂️ Navigation Integration

  • Added to Fundamentals section in docs/toc.yml with appropriate search keywords

Key Features Addressed

General usage documentation: Comprehensive coverage of how annotations work across the dashboard, deployment tools, testing infrastructure, and hosting layer

Custom annotation creation: Complete implementation guide showing how to:

// 1. Define custom annotation
public sealed class CustomConfigAnnotation : IResourceAnnotation
{
    public string ConfigKey { get; set; } = "";
    public string ConfigValue { get; set; } = "";
}

// 2. Create extension methods
public static IResourceBuilder<T> WithCustomConfig<T>(
    this IResourceBuilder<T> builder, string key, string value)
    where T : class, IResource
{
    return builder.WithAnnotation(new CustomConfigAnnotation 
    { 
        ConfigKey = key, 
        ConfigValue = value 
    });
}

// 3. Use in app host
var api = builder.AddProject<Projects.Api>("api")
    .WithCustomConfig("feature-flag", "enabled");

Quality Assurance

  • ✅ All markdown linting passes
  • ✅ All code examples compile successfully
  • ✅ Follows Microsoft Writing Style Guide conventions
  • ✅ Proper API cross-references using <xref> syntax
  • ✅ Consistent with existing .NET Aspire documentation patterns

This documentation provides developers with the knowledge needed to effectively use and extend .NET Aspire's annotation system, filling a critical gap in the current documentation set.

Fixes #1614.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/fundamentals/annotations-overview.md Resource annotations in .NET Aspire
docs/toc.yml docs/toc

@Copilot Copilot AI changed the title [WIP] Annotations documentation Add comprehensive annotations documentation for .NET Aspire Jul 15, 2025
@Copilot Copilot AI requested a review from IEvangelist July 15, 2025 17:59
Copilot finished work on behalf of IEvangelist July 15, 2025 17:59
@Copilot Copilot AI requested a review from IEvangelist July 15, 2025 20:28
Copilot finished work on behalf of IEvangelist July 15, 2025 20:28
@Copilot Copilot AI requested a review from IEvangelist July 16, 2025 14:10
Copilot finished work on behalf of IEvangelist July 16, 2025 14:10
@Copilot Copilot AI requested a review from IEvangelist July 16, 2025 16:10
Copilot finished work on behalf of IEvangelist July 16, 2025 16:10
@Copilot Copilot AI requested a review from IEvangelist July 16, 2025 16:13
Copilot finished work on behalf of IEvangelist July 16, 2025 16:13
Copilot finished work on behalf of IEvangelist July 16, 2025 16:18
@IEvangelist IEvangelist marked this pull request as ready for review July 16, 2025 16:25
@IEvangelist IEvangelist requested review from tdykstra and adegeo July 16, 2025 16:28
- <xref:Aspire.Hosting.ResourceBuilderExtensions.WithCommand*> adds a <xref:Aspire.Hosting.ApplicationModel.ResourceCommandAnnotation> that defines a custom command.
- <xref:Aspire.Hosting.ResourceBuilderExtensions.WithUrl*> adds a <xref:Aspire.Hosting.ApplicationModel.ResourceUrlAnnotation> that defines a custom URL.

## Built-in annotation types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exhuastive. @IEvangelist is it supposed to be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotations documentation
3 participants