AzureContainerRegistryExtensions Methods
Class Methods 5 members
Provides extension methods for adding Azure Container Registry resources to the application model.
AddAzureContainerRegistry(IDistributedApplicationBuilder, string) Section titled AddAzureContainerRegistry(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureContainerRegistryResource> Adds an Azure Container Registry resource to the application model.
public static class AzureContainerRegistryExtensions{ public static IResourceBuilder<AzureContainerRegistryResource> AddAzureContainerRegistry( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builder IDistributedApplicationBuilder The builder for the distributed application. name string The name of the resource. Returns
IResourceBuilder<AzureContainerRegistryResource> A reference to the ApplicationModel.IResourceBuilder`1 builder. Exceptions
ArgumentNullException Thrown when builder is null. ArgumentException Thrown when name is null or empty. GetAzureContainerRegistry(IResourceBuilder<T>) Section titled GetAzureContainerRegistry(IResourceBuilder<T>) extension IResourceBuilder<AzureContainerRegistryResource> Gets the
AzureContainerRegistryResource associated with the specified Azure compute environment resource. public static class AzureContainerRegistryExtensions{ public static IResourceBuilder<AzureContainerRegistryResource> GetAzureContainerRegistry<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builder IResourceBuilder<T> The resource builder for the compute environment resource. Returns
IResourceBuilder<AzureContainerRegistryResource> A reference to the ApplicationModel.IResourceBuilder`1 for the associated registry. Exceptions
ArgumentNullException Thrown when builder is null. InvalidOperationException Thrown when the resource does not have an associated Azure Container Registry, or when the associated container registry is not an AzureContainerRegistryResource. WithAzureContainerRegistry(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>) Section titled WithAzureContainerRegistry(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>) extension IResourceBuilder<T> Configures a resource that implements
ApplicationModel.IContainerRegistry to use the specified Azure Container Registry. public static class AzureContainerRegistryExtensions{ public static IResourceBuilder<T> WithAzureContainerRegistry<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureContainerRegistryResource> registryBuilder) { // ... }}Parameters
builder IResourceBuilder<T> The resource builder for a resource that implements ApplicationModel.IContainerRegistry. registryBuilder IResourceBuilder<AzureContainerRegistryResource> The resource builder for the AzureContainerRegistryResource to use. Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1. Exceptions
ArgumentNullException Thrown when builder or registryBuilder is null. WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?) Section titled WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?) extension IResourceBuilder<AzureContainerRegistryResource> Adds a scheduled ACR purge task to remove old or unused container images from the registry.
public static class AzureContainerRegistryExtensions{ public static IResourceBuilder<AzureContainerRegistryResource> WithPurgeTask( this IResourceBuilder<AzureContainerRegistryResource> builder, string schedule, string? filter = null, TimeSpan? ago = null, int keep = 3, string? taskName = null) { // ... }}Parameters
builder IResourceBuilder<AzureContainerRegistryResource> The resource builder for the AzureContainerRegistryResource. schedule string The cron schedule for the purge task timer trigger. Must be a five-part cron expression ( minute hour day-of-month month day-of-week); seconds are not supported. filter string? optional An optional filter for the acr purge --filter parameter. Only repositories matching this filter will be purged. Defaults to ".*:.*" (all repositories and tags) when null. ago TimeSpan? optional The age threshold for acr purge --ago. Images older than this duration will be considered for removal. Uses Go-style duration format (e.g., 2d3h6m). Defaults to 0d when null. keep int optional The number of most recent images to keep per repository, regardless of age. Must be greater than zero. Defaults to 3. taskName string? optional An optional name for the ACR task resource. If not provided, a name is auto-generated based on existing purge tasks to avoid conflicts. If a task with the specified name already exists, an ArgumentException is thrown. Returns
IResourceBuilder<AzureContainerRegistryResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining. Exceptions
ArgumentNullException Thrown when builder is null. ArgumentException Thrown when schedule is null, empty, or whitespace, or when taskName conflicts with an existing task. ArgumentOutOfRangeException Thrown when keep is less than 1, or ago is negative or less than 1 minute (when non-zero). Examples
This example configures a daily purge task that removes images older than 7 days, keeping the 5 most recent:
var acr = builder.AddAzureContainerRegistry("myregistry") .WithPurgeTask("0 1 * * *", ago: TimeSpan.FromDays(7), keep: 5);WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>, ContainerRegistryBuiltInRole[]) Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>, ContainerRegistryBuiltInRole[]) extension IResourceBuilder<T> Adds role assignments to the specified Azure Container Registry resource.
public static class AzureContainerRegistryExtensions{ public static IResourceBuilder<T> WithRoleAssignments<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureContainerRegistryResource> target, params ContainerRegistryBuiltInRole[] roles) { // ... }}Parameters
builder IResourceBuilder<T> The resource builder for the resource that will have role assignments. target IResourceBuilder<AzureContainerRegistryResource> The target Azure Container Registry resource. roles ContainerRegistryBuiltInRole[] The roles to assign to the resource. Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
This overload is not available in polyglot app hosts. Use
AzureContainerRegistryExtensions.WithRoleAssignments instead.