# YarpResourceExtensions Methods

- Package: [Aspire.Hosting.Yarp](/reference/api/csharp/aspire.hosting.yarp.md)
- Type: [YarpResourceExtensions](/reference/api/csharp/aspire.hosting.yarp/yarpresourceextensions.md)
- Kind: `Methods`
- Members: `7`

Provides extension methods for adding YARP resources to the application model.

## AddYarp(IDistributedApplicationBuilder, string)

- Name: `AddYarp(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L35-L99)

Adds a YARP container to the application model.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> AddYarp(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## PublishWithStaticFiles(IResourceBuilder<YarpResource>, IResourceBuilder<IResourceWithContainerFiles>)

- Name: `PublishWithStaticFiles(IResourceBuilder<YarpResource>, IResourceBuilder<IResourceWithContainerFiles>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L228-L237)

In publish mode, generates a Dockerfile that copies static files from the specified resource into /app/wwwroot.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> PublishWithStaticFiles(
        this IResourceBuilder<YarpResource> builder,
        IResourceBuilder<IResourceWithContainerFiles> resourceWithFiles)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The resource builder for YARP.
- `resourceWithFiles` (`IResourceBuilder<IResourceWithContainerFiles>`)
  The resource with container files.

## Returns

`IResourceBuilder<YarpResource>` -- The updated resource builder.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithConfiguration(IResourceBuilder<YarpResource>, Action<IYarpConfigurationBuilder>)

- Name: `WithConfiguration(IResourceBuilder<YarpResource>, Action<IYarpConfigurationBuilder>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L110-L112)

Configure the YARP resource.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> WithConfiguration(
        this IResourceBuilder<YarpResource> builder,
        Action<IYarpConfigurationBuilder> configurationBuilder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The YARP resource to configure.
- `configurationBuilder` (`Action<IYarpConfigurationBuilder>`)
  The delegate to configure YARP.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostHttpsPort(IResourceBuilder<YarpResource>, int?)

- Name: `WithHostHttpsPort(IResourceBuilder<YarpResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L141-L145)

Configures the host HTTPS port that the YARP resource is exposed on instead of using randomly assigned port. This will only have effect if an HTTPS endpoint is configured on the YARP resource due to TLS termination being enabled.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> WithHostHttpsPort(
        this IResourceBuilder<YarpResource> builder,
        int? port)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The resource builder for YARP.
- `port` (`int?`)
  The port to bind on the host. If `null` is used random port will be assigned.

## Returns

`IResourceBuilder<YarpResource>` -- The updated resource builder.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostPort(IResourceBuilder<YarpResource>, int?)

- Name: `WithHostPort(IResourceBuilder<YarpResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L123-L128)

Configures the host port that the YARP resource is exposed on instead of using randomly assigned port.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> WithHostPort(
        this IResourceBuilder<YarpResource> builder,
        int? port)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The resource builder for YARP.
- `port` (`int?`)
  The port to bind on the host. If `null` is used random port will be assigned.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithStaticFiles(IResourceBuilder<YarpResource>)

- Name: `WithStaticFiles(IResourceBuilder<YarpResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L156-L158)

Enables static file serving in the YARP resource. Static files are served from the wwwroot folder.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> WithStaticFiles(
        this IResourceBuilder<YarpResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The resource builder for YARP.

## Returns

`IResourceBuilder<YarpResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithStaticFiles(IResourceBuilder<YarpResource>, string)

- Name: `WithStaticFiles(IResourceBuilder<YarpResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<YarpResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L172-L175)

Enables static file serving. In run mode: bind mounts `sourcePath` to /wwwroot. In publish mode: generates a Dockerfile whose build context is `sourcePath` and copies its contents into /app/wwwroot baked into the image.

```csharp
public static class YarpResourceExtensions
{
    public static IResourceBuilder<YarpResource> WithStaticFiles(
        this IResourceBuilder<YarpResource> builder,
        string sourcePath)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<YarpResource>`)
  The resource builder for YARP.
- `sourcePath` (`string`)
  The source path containing static files to serve.

## Returns

`IResourceBuilder<YarpResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
