# FlagdBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Flagd](/reference/api/csharp/communitytoolkit.aspire.hosting.flagd.md)
- Type: [FlagdBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.flagd/flagdbuilderextensions.md)
- Kind: `Methods`
- Members: `3`

Provides extension methods for adding flagd resources to an `Hosting.IDistributedApplicationBuilder`.

## AddFlagd(IDistributedApplicationBuilder, string, int?, int?)

- Name: `AddFlagd(IDistributedApplicationBuilder, string, int?, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FlagdResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Flagd/FlagdBuilderExtensions.cs#L34-L47)

Adds a flagd container to the application model.

```csharp
public static class FlagdBuilderExtensions
{
    public static IResourceBuilder<FlagdResource> AddFlagd(
        this IDistributedApplicationBuilder builder,
        string name,
        int? port = null,
        int? ofrepPort = null)
    {
        // ...
    }
}
```

## 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.
- `port` (`int?`) `optional`
  The host port for flagd HTTP endpoint. If not provided, a random port will be assigned.
- `ofrepPort` (`int?`) `optional`
  The host port for flagd OFREP endpoint. If not provided, a random port will be assigned.

## Returns

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

## Remarks

The flagd container requires a sync source to be configured.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithBindFileSync(IResourceBuilder<FlagdResource>, string, string)

- Name: `WithBindFileSync(IResourceBuilder<FlagdResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FlagdResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Flagd/FlagdBuilderExtensions.cs#L89-L94)

Configures flagd to use a bind mount as the source of flags.

```csharp
public static class FlagdBuilderExtensions
{
    public static IResourceBuilder<FlagdResource> WithBindFileSync(
        this IResourceBuilder<FlagdResource> builder,
        string fileSource,
        string filename = "flagd.json")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FlagdResource>`)
  The resource builder.
- `fileSource` (`string`)
  The path to the host directory that contains the flag configuration file.
- `filename` (`string`) `optional`
  The name of the flag configuration file. Defaults to "flagd.json".

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithLogLevel(IResourceBuilder<FlagdResource>, LogLevel)

- Name: `WithLogLevel(IResourceBuilder<FlagdResource>, LogLevel)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FlagdResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Flagd/FlagdBuilderExtensions.cs#L66-L73)

Configures logging level for flagd. If a flag or targeting rule isn't proceeding the way you'd expect this can be enabled to get more verbose logging.

```csharp
public static class FlagdBuilderExtensions
{
    public static IResourceBuilder<FlagdResource> WithLogLevel(
        this IResourceBuilder<FlagdResource> builder,
        LogLevel logLevel)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FlagdResource>`)
  The resource builder.
- `logLevel` (`LogLevel`)
  The log level to use. Currently only debug is supported.

## Returns

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

## Exceptions

- `InvalidOperationException` -- Thrown if the log level is not valid.

## Remarks

Currently only debug is supported. This method is not available in polyglot app hosts. Configure the `FLAGD_DEBUG` environment variable directly instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
