# AzureSubnetResource.WithServiceDelegation

- Module: [Aspire.Hosting.Azure.Network](/reference/api/go/aspire.hosting.azure.network.md)
- Defined on: [AzureSubnetResource](/reference/api/go/aspire.hosting.azure.network/azuresubnetresource.md)
- Version: `17.0.0`
- Kind: `method`

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
type AzureSubnetResource interface {
    // ... omitted for brevity
    WithServiceDelegation(
        serviceName string,
        options ...*WithServiceDelegationOptions,
    ) AzureSubnetResource
}
```

## Signature

```go
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()`.

## Defined on

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