# WithServiceDelegation

- Module: [Aspire.Hosting.Azure.Network](/reference/api/go/aspire.hosting.azure.network.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`AzureSubnetResource`](/reference/api/go/aspire.hosting.azure.network/azuresubnetresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Delegates the subnet to the specified Azure service.

## Remarks

Service delegation grants the specified Azure service permission to create service-specific
resources in the subnet. Azure subnets can carry more than one delegation, but Aspire models a
subnet with a single delegation and emits only the most recent one. Calling this multiple times,
or combining it with `WithDelegatedSubnet`, therefore replaces any previously
configured delegation with the latest value (last-write-wins).

## Definition

```go
func (AzureSubnetResource) WithServiceDelegation(
    serviceName string,
    options ...*WithServiceDelegationOptions,
) AzureSubnetResource
```

## Parameters

- `serviceName` (`string`) -- The service name to delegate the subnet to (e.g., "Microsoft.App/environments"). See `AzureSubnetServiceDelegations` for well-known values.
- `options` (`...*WithServiceDelegationOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithServiceDelegationOptions` argument.

- `Name` (`*string`) -- The name of the service delegation. If not specified, defaults to `serviceName`.

## Returns

[`AzureSubnetResource`](/reference/api/go/aspire.hosting.azure.network/azuresubnetresource.md) -- The resource builder.

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

## Applies to

- [`AzureSubnetResource`](/reference/api/go/aspire.hosting.azure.network/azuresubnetresource.md)
