# RadiusExtensions Methods

- Package: [Aspire.Hosting.Radius](/reference/api/csharp/aspire.hosting.radius.md)
- Type: [RadiusExtensions](/reference/api/csharp/aspire.hosting.radius/radiusextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding and configuring Radius environment resources.

<a id="addradiusenvironment"></a>
<a id="addradiusenvironment-idistributedapplicationbuilder-string"></a>

## AddRadiusEnvironment(IDistributedApplicationBuilder, string)

- Name: `AddRadiusEnvironment(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RadiusEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Radius/RadiusExtensions.cs#L37-L53)

Adds a Radius compute environment to the application model.

```csharp
public static class RadiusExtensions
{
    public static IResourceBuilder<RadiusEnvironmentResource> AddRadiusEnvironment(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the Radius environment resource.

## Returns

`IResourceBuilder<RadiusEnvironmentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

In `DistributedApplicationOperation.Run` mode this returns an unregistered builder so the environment does not surface as a resource in the dashboard and no pipeline steps are wired up -- matching `AddKubernetesEnvironment` and `AddDockerComposeEnvironment`. All deployment-target wiring runs in Publish mode only.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="configureradiusinfrastructure"></a>
<a id="configureradiusinfrastructure-iresourcebuilder-radiusenvironmentresource-action-radiusinfrastructureoptions"></a>

## ConfigureRadiusInfrastructure(IResourceBuilder<RadiusEnvironmentResource>, Action<RadiusInfrastructureOptions>)

> **Experimental:** ASPIRERADIUS004 - [Learn more](/diagnostics/aspireradius004/)

- Name: `ConfigureRadiusInfrastructure(IResourceBuilder<RadiusEnvironmentResource>, Action<RadiusInfrastructureOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RadiusEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Radius/RadiusExtensions.cs#L96-L100)

Registers a callback that can customize the generated Radius infrastructure before Bicep is emitted.

```csharp
public static class RadiusExtensions
{
    public static IResourceBuilder<RadiusEnvironmentResource> ConfigureRadiusInfrastructure(
        this IResourceBuilder<RadiusEnvironmentResource> builder,
        Action<RadiusInfrastructureOptions> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RadiusEnvironmentResource>`)
  The Radius environment resource builder.
- `configure` (`Action<RadiusInfrastructureOptions>`)
  The callback that mutates the generated infrastructure options.

## Returns

`IResourceBuilder<RadiusEnvironmentResource>` -- The same `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### Ignored by ATS

- Reason: RadiusInfrastructureOptions customization callbacks are not ATS-compatible.

<a id="withcontainerimage"></a>
<a id="withcontainerimage-iresourcebuilder-projectresource-string"></a>

## WithContainerImage(IResourceBuilder<ProjectResource>, string)

> **Experimental:** ASPIRERADIUS057 - [Learn more](/diagnostics/aspireradius057/)

- Name: `WithContainerImage(IResourceBuilder<ProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Radius/RadiusExtensions.cs#L137-L157)

Associates a pre-built container image reference with a project resource so the Aspire.Hosting.Radius publisher can emit a valid Radius container manifest for it.

```csharp
public static class RadiusExtensions
{
    public static IResourceBuilder<ProjectResource> WithContainerImage(
        this IResourceBuilder<ProjectResource> builder,
        string image)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The project resource builder.
- `image` (`string`)
  A fully-qualified image reference in `[registry/]image[:tag]` form (for example `localhost:5001/apiservice:latest`). When the tag is omitted `latest` is used.

## Returns

`IResourceBuilder<ProjectResource>` -- The same `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

The Radius publisher does not yet build or push images for `ApplicationModel.ProjectResource` (tracked at https://github.com/microsoft/aspire/issues/16844). Until that lands, callers must build and push the image themselves (for example with `dotnet publish /t:PublishContainer`) and then call this method to attach the resulting registry reference. Without it, `aspire publish` against a Radius environment fails with a clear remediation message -- and `aspire deploy` against Radius would otherwise land pods that hit `ImagePullBackOff` against the publisher's `<name>:latest` fallback. The reference is stored as a `ApplicationModel.ContainerImageAnnotation`, which is also what container resources use, so the publisher's existing `Registry` / `Image` / `Tag` assembly path applies uniformly.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withnamespace"></a>
<a id="withnamespace-iresourcebuilder-radiusenvironmentresource-string"></a>

## WithNamespace(IResourceBuilder<RadiusEnvironmentResource>, string)

- Name: `WithNamespace(IResourceBuilder<RadiusEnvironmentResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RadiusEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Radius/RadiusExtensions.cs#L68-L81)

Sets the Kubernetes namespace for the Radius environment.

```csharp
public static class RadiusExtensions
{
    public static IResourceBuilder<RadiusEnvironmentResource> WithNamespace(
        this IResourceBuilder<RadiusEnvironmentResource> builder,
        string kubernetesNamespace)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RadiusEnvironmentResource>`)
  The Radius environment resource builder.
- `kubernetesNamespace` (`string`)
  A valid RFC 1123 namespace name.

## Returns

`IResourceBuilder<RadiusEnvironmentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Exceptions

- `ArgumentException` -- Thrown when the namespace is not a valid RFC 1123 label.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
