Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

This pull request introduces a new interface, IAzureContainerRegistryResource, and updates the Azure compute environment resources to consistently expose and validate their associated Azure Container Registry resources. It also adds comprehensive tests to ensure correct behavior and validation when configuring container registries for Azure App Service and Container App environments.

Key changes include:

API and Interface Improvements

  • Introduced the IAzureContainerRegistryResource interface to represent Azure-specific container registry resources, and updated AzureContainerRegistryResource to implement this new interface. [1] [2]
  • Updated the IAzureComputeEnvironmentResource interface to include a strongly typed ContainerRegistry property of type IAzureContainerRegistryResource, ensuring all compute environments expose their Azure container registry in a consistent way.

Resource Property and Validation Enhancements

  • Added a ContainerRegistry property to both AzureContainerAppEnvironmentResource and AzureAppServiceEnvironmentResource, which throws a clear exception if no registry is configured or if a non-Azure registry is set, enforcing correct usage. [1] [2]
  • Implemented the new interface property in both environment resources to return the strongly typed registry. [1] [2]

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No
Original prompt

This section details on the original issue you should resolve

<issue_title>Expose Azure Compute Environment's Container Registry</issue_title>
<issue_description>There are scenarios where consumers need to get access to the Azure Container Registry that an ACA or App Service Environment is going to use. For example, to set up additional roles / permissions to the ACR.

We should add a new interface that both ACA Environment Resource and App Service Environment Resource implement that exposes a method or property to retrieve the AzureContainerRegistryResource used by the compute environment. Its implementation should be the same as this method:

private IContainerRegistry? GetContainerRegistry()
{
// Check for explicit container registry reference annotation
if (this.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var annotation))
{
return annotation.Registry;
}
// Fall back to default container registry
return DefaultContainerRegistry;
}

But it shouldn't be nullable. It has to return a non-null instance. If there is no annotation, and the DefaultContainerRegistry is null, an exception should be thrown.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 5, 2026 23:27
…mentation

Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
…prove error handling

Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Copilot AI changed the title [WIP] Expose Azure Compute Environment's Container Registry Expose Azure Container Registry from compute environments via public API Jan 5, 2026
Copilot AI requested a review from eerhardt January 5, 2026 23:48
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

@copilot please implement the feedback

Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Copilot AI changed the title Expose Azure Container Registry from compute environments via public API Expose Azure Container Registry from compute environments via ContainerRegistry property Jan 6, 2026
Copilot AI requested a review from eerhardt January 6, 2026 22:03
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13755

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13755"

@eerhardt eerhardt marked this pull request as ready for review January 8, 2026 21:52
@eerhardt eerhardt requested a review from captainsafia as a code owner January 8, 2026 21:52
Copilot AI review requested due to automatic review settings January 8, 2026 21:52
}
}

ReferenceExpression IAzureContainerRegistry.ManagedIdentityId => ReferenceExpression.Create($"{ContainerRegistryManagedIdentityId}");
Copy link
Member

Choose a reason for hiding this comment

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

@davidfowl @captainsafia - what you think about obsoleting the IAzureContainerRegistry interface? I think we made a mistake in designing it. It is more like "IAzureContainerRegistryInformation" or "IAzureContainerRegistryReference" - it doesn't really represent a registry, but instead a reference to a registry.

The ManagedIdentityId property on it is odd - it is the identity that the compute environment uses to pull from the registry, not the identity of the registry itself.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes the Azure Container Registry used by Azure compute environments (Azure Container Apps and App Service) through a new public API, enabling consumers to programmatically access and configure the registry for scenarios like setting up additional roles and permissions.

Key Changes:

  • Introduces IAzureContainerRegistryResource interface that combines Azure resource and container registry capabilities
  • Extends IAzureComputeEnvironmentResource interface with a non-nullable ContainerRegistry property
  • Implements the property in both AzureContainerAppEnvironmentResource and AzureAppServiceEnvironmentResource with validation logic
  • Adds comprehensive test coverage for all scenarios including default registry, explicit registry, and error cases

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Aspire.Hosting.Azure/IAzureContainerRegistryResource.cs New interface combining IAzureResource and IContainerRegistry for Azure Container Registry resources
src/Aspire.Hosting.Azure/IAzureComputeEnvironmentResource.cs Extended interface with ContainerRegistry property returning IAzureContainerRegistryResource
src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryResource.cs Updated to implement new IAzureContainerRegistryResource interface instead of IContainerRegistry directly
src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs Implements ContainerRegistry property with validation, throws exceptions for unconfigured or non-Azure registries
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs Implements ContainerRegistry property with validation, throws exceptions for unconfigured or non-Azure registries
tests/Aspire.Hosting.Azure.Tests/AzureContainerAppEnvironmentExtensionsTests.cs Comprehensive tests covering default registry, explicit registry preference, and error scenarios
tests/Aspire.Hosting.Azure.Tests/AzureAppServiceEnvironmentExtensionsTests.cs Comprehensive tests covering default registry, explicit registry preference, and error scenarios

Comment on lines +13 to +16
/// <summary>
/// Gets the Azure Container Registry resource used by this compute environment.
/// </summary>
IAzureContainerRegistryResource ContainerRegistry { get => throw new NotImplementedException(); }
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The interface documentation should follow Aspire's XML documentation guidelines more closely. According to guideline 1000002, public API documentation should include remarks with additional context about when and how to use the API. Consider adding a remarks section explaining scenarios where consumers would use this property, such as configuring additional roles, permissions, or ACR settings.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +196 to +219
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure Container App Environment resource.
/// </summary>
public AzureContainerRegistryResource ContainerRegistry
{
get
{
var registry = GetContainerRegistry();

if (registry is null)
{
throw new InvalidOperationException($"No container registry is configured for the Azure Container App Environment '{Name}'.");
}

if (registry is AzureContainerRegistryResource azureRegistry)
{
return azureRegistry;
}

throw new InvalidOperationException(
$"The container registry configured for the Azure Container App Environment '{Name}' is not an Azure Container Registry. " +
$"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.");
}
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

According to Aspire's XML documentation guidelines (guideline 1000002), public API properties should include remarks and example sections for clarity. The property documentation should explain when exceptions are thrown and provide usage examples. Consider adding:

  • A remarks section explaining the validation behavior and when to use this property
  • An example section showing practical usage
  • Exception tags documenting the InvalidOperationException scenarios

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +234 to +257
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure App Service Environment resource.
/// </summary>
public AzureContainerRegistryResource ContainerRegistry
{
get
{
var registry = GetContainerRegistry();

if (registry is null)
{
throw new InvalidOperationException($"No container registry is configured for the Azure App Service Environment '{Name}'.");
}

if (registry is AzureContainerRegistryResource azureRegistry)
{
return azureRegistry;
}

throw new InvalidOperationException(
$"The container registry configured for the Azure App Service Environment '{Name}' is not an Azure Container Registry. " +
$"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.");
}
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

According to Aspire's XML documentation guidelines (guideline 1000002), public API properties should include remarks and example sections for clarity. The property documentation should explain when exceptions are thrown and provide usage examples. Consider adding:

  • A remarks section explaining the validation behavior and when to use this property
  • An example section showing practical usage
  • Exception tags documenting the InvalidOperationException scenarios

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +8 to +13
/// <summary>
/// Represents an Azure Container Registry resource.
/// </summary>
public interface IAzureContainerRegistryResource : IContainerRegistry, IAzureResource
{
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

According to Aspire's XML documentation guidelines (guideline 1000002), public API interfaces should include a remarks section providing additional context about when and how to use the interface. Consider adding:

  • A remarks section explaining that this interface combines Azure resource capabilities with container registry functionality
  • A seealso reference to related types like IAzureComputeEnvironmentResource or AzureContainerRegistryResource

Copilot generated this review using guidance from repository custom instructions.
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure Container App Environment resource.
/// </summary>
public AzureContainerRegistryResource ContainerRegistry
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The new public property ContainerRegistry on AzureContainerAppEnvironmentResource is missing from the auto-generated API file. Since this is a public API addition, it needs to be tracked in the API surface file. The API files should be regenerated after adding this property.

Similarly, the new interface IAzureContainerRegistryResource and the updated IAzureComputeEnvironmentResource interface with its new ContainerRegistry property need to be included in the appropriate API files.

Copilot uses AI. Check for mistakes.
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure App Service Environment resource.
/// </summary>
public AzureContainerRegistryResource ContainerRegistry
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The new public property ContainerRegistry on AzureAppServiceEnvironmentResource is missing from the auto-generated API file. Since this is a public API addition, it needs to be tracked in the API surface file. The API files should be regenerated after adding this property.

Suggested change
public AzureContainerRegistryResource ContainerRegistry
internal AzureContainerRegistryResource ContainerRegistry

Copilot uses AI. Check for mistakes.
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.

Expose Azure Compute Environment's Container Registry

3 participants