AzureContainerRegistryExtensions Methods
ClassMethods5 members
Provides extension methods for adding Azure Container Registry resources to the application model.
AddAzureContainerRegistry(IDistributedApplicationBuilder, string)Section titled AddAzureContainerRegistry(IDistributedApplicationBuilder, string)extensionIResourceBuilder<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
builderIDistributedApplicationBuilderThe builder for the distributed application.namestringThe name of the resource.Returns
IResourceBuilder<AzureContainerRegistryResource>A reference to the ApplicationModel.IResourceBuilder`1 builder.Exceptions
ArgumentNullExceptionThrown when builder is null.ArgumentExceptionThrown when name is null or empty.GetAzureContainerRegistry(IResourceBuilder<T>)Section titled GetAzureContainerRegistry(IResourceBuilder<T>)extensionIResourceBuilder<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
builderIResourceBuilder<T>The resource builder for the compute environment resource.Returns
IResourceBuilder<AzureContainerRegistryResource>A reference to the ApplicationModel.IResourceBuilder`1 for the associated registry.Exceptions
ArgumentNullExceptionThrown when builder is null.InvalidOperationExceptionThrown 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>)extensionIResourceBuilder<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
builderIResourceBuilder<T>The resource builder for a resource that implements ApplicationModel.IContainerRegistry.registryBuilderIResourceBuilder<AzureContainerRegistryResource>The resource builder for the AzureContainerRegistryResource to use.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentNullExceptionThrown when builder or registryBuilder is null.WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?)Section titled WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?)extensionIResourceBuilder<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
builderIResourceBuilder<AzureContainerRegistryResource>The resource builder for the AzureContainerRegistryResource.schedulestringThe 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.filterstring?optionalAn optional filter for the acr purge --filter parameter. Only repositories matching this filter will be purged. Defaults to ".*:.*" (all repositories and tags) when null.agoTimeSpan?optionalThe 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.keepintoptionalThe number of most recent images to keep per repository, regardless of age. Must be greater than zero. Defaults to 3.taskNamestring?optionalAn 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
ArgumentNullExceptionThrown when builder is null.ArgumentExceptionThrown when schedule is null, empty, or whitespace, or when taskName conflicts with an existing task.ArgumentOutOfRangeExceptionThrown 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[])extensionIResourceBuilder<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
builderIResourceBuilder<T>The resource builder for the resource that will have role assignments.targetIResourceBuilder<AzureContainerRegistryResource>The target Azure Container Registry resource.rolesContainerRegistryBuiltInRole[]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.