# WithUniqueResourceNaming

- Module: [Aspire.Hosting.Azure.AppContainers](/reference/api/go/aspire.hosting.azure.appcontainers.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`AzureContainerAppEnvironmentResource`](/reference/api/go/aspire.hosting.azure.appcontainers/azurecontainerappenvironmentresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Configures the container app environment to incorporate its resource name into the generated managed environment `name`, so that multiple environments in the same resource group get distinct names.

## Remarks

By default the managed environment relies on Azure.Provisioning's name, whose sanitizer keeps only
lowercase letters. For example, two `AddAzureContainerAppEnvironment` resources named
`cae1` and `cae2` both drop their trailing digit and yield
`take('cae${uniqueString(resourceGroup().id)}', 24)`. When they share a resource group,
that default would collapse both onto a single physical environment and concurrent
container-app writes would race with `ManagedEnvironmentOperationInProgress`. Publish and deploy
detect this collision and fail with guidance to apply this method instead
(see ).
Applying this method computes the managed environment `name` with the same algorithm Azure.Provisioning
uses for every other Azure resource type (sanitized resource name, then a hyphen separator and a
`uniqueString(resourceGroup().id)` suffix, truncated to the maximum length), but with the character
requirements Azure Container Apps managed environments actually allow -- lowercase letters, digits, and
hyphens, with a 60-character maximum. For example, `cae1` produces
`take('cae1-${uniqueString(resourceGroup().id)}', 60)`, while `prod1` uses a `prod1`
prefix. Preserving the digits gives each environment a distinct `name`. This is opt-in because
enabling it changes the environment `name` for an already-deployed single environment, which would
cause Azure to recreate it. Apply it only to the environments that need distinct names (typically when
deploying more than one environment to a single resource group), or to new deployments.
This option acts as a fallback after name resolvers configured through
`ProvisioningBuildOptions`. A configured resolver can therefore
override the generated name. This option also has no effect when `WithAzdResourceNaming` is
used, since azd naming sets the environment name explicitly.

## Definition

```go
func (AzureContainerAppEnvironmentResource) WithUniqueResourceNaming() AzureContainerAppEnvironmentResource
```

## Returns

[`AzureContainerAppEnvironmentResource`](/reference/api/go/aspire.hosting.azure.appcontainers/azurecontainerappenvironmentresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`AzureContainerAppEnvironmentResource`](/reference/api/go/aspire.hosting.azure.appcontainers/azurecontainerappenvironmentresource.md)
