# AzureKustoBuilderExtensions Methods

- Package: [Aspire.Hosting.Azure.Kusto](/reference/api/csharp/aspire.hosting.azure.kusto.md)
- Type: [AzureKustoBuilderExtensions](/reference/api/csharp/aspire.hosting.azure.kusto/azurekustobuilderextensions.md)
- Kind: `Methods`
- Members: `5`

Extension methods for adding Kusto resources to the application model.

## AddAzureKustoCluster(IDistributedApplicationBuilder, string)

- Name: `AddAzureKustoCluster(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureKustoClusterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L49-L98)

Adds an Azure Data Explorer (Kusto) cluster resource to the application model.

```csharp
public static class AzureKustoBuilderExtensions
{
    public static IResourceBuilder<AzureKustoClusterResource> AddAzureKustoCluster(
        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<AzureKustoClusterResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

When adding an [AzureKustoClusterResource](/reference/api/csharp/aspire.hosting.azure.kusto/azurekustoclusterresource.md) to your application model the resource can then be referenced by other resources using the resource name. When the dependent resource is using the extension method `ResourceBuilderExtensions.WaitFor` then the dependent resource will wait until the Kusto database is available.

By default references to the Azure Data Explorer database resources will be assigned the following roles: - `KustoDatabasePrincipalRole.User`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddReadWriteDatabase(IResourceBuilder<AzureKustoClusterResource>, string, string?)

- Name: `AddReadWriteDatabase(IResourceBuilder<AzureKustoClusterResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureKustoReadWriteDatabaseResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L112-L141)

Adds a Kusto read-write database to the application model.

```csharp
public static class AzureKustoBuilderExtensions
{
    public static IResourceBuilder<AzureKustoReadWriteDatabaseResource> AddReadWriteDatabase(
        this IResourceBuilder<AzureKustoClusterResource> builder,
        string name,
        string? databaseName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureKustoClusterResource>`)
  The Kusto server resource builder.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.
- `databaseName` (`string?`) `optional`
  The name of the database. If not provided, this defaults to the same value as `name`.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## RunAsEmulator(IResourceBuilder<AzureKustoClusterResource>, Action<IResourceBuilder<AzureKustoEmulatorResource>>)

- Name: `RunAsEmulator(IResourceBuilder<AzureKustoClusterResource>, Action<IResourceBuilder<AzureKustoEmulatorResource>>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureKustoClusterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L160-L187)

Configures the Kusto resource to run as an emulator using the Kustainer container.

```csharp
public static class AzureKustoBuilderExtensions
{
    public static IResourceBuilder<AzureKustoClusterResource> RunAsEmulator(
        this IResourceBuilder<AzureKustoClusterResource> builder,
        Action<IResourceBuilder<AzureKustoEmulatorResource>>? configureContainer = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureKustoClusterResource>`)
  The resource builder to configure.
- `configureContainer` (`Action<IResourceBuilder<AzureKustoEmulatorResource>>`) `optional`
  Optional action to configure the Kusto emulator container.

## Returns

`IResourceBuilder<AzureKustoClusterResource>` -- The resource builder.

## Remarks

This version of the package defaults to the tag of the / container image.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithCreationScript(IResourceBuilder<AzureKustoReadWriteDatabaseResource>, string)

- Name: `WithCreationScript(IResourceBuilder<AzureKustoReadWriteDatabaseResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureKustoReadWriteDatabaseResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L203-L209)

Defines the script used to create the database.

```csharp
public static class AzureKustoBuilderExtensions
{
    public static IResourceBuilder<AzureKustoReadWriteDatabaseResource> WithCreationScript(
        this IResourceBuilder<AzureKustoReadWriteDatabaseResource> builder,
        string script)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureKustoReadWriteDatabaseResource>`)
  The resource builder to configure.
- `script` (`string`)
  KQL script to create databases, tables, or data.

## Returns

`IResourceBuilder<AzureKustoReadWriteDatabaseResource>` -- The resource builder.

## Remarks

This script will only be executed when the Kusto resource is running in emulator mode. In production scenarios, the database creation should be handled as part of the provisioning process.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostPort(IResourceBuilder<AzureKustoEmulatorResource>, int)

- Name: `WithHostPort(IResourceBuilder<AzureKustoEmulatorResource>, int)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureKustoEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L222-L227)

Configures the host port that the Kusto emulator listens on for HTTP query requests.

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

## Parameters

- `builder` (`IResourceBuilder<AzureKustoEmulatorResource>`)
  Kusto emulator resource builder.
- `port` (`int`)
  Host port to use.

## Returns

`IResourceBuilder<AzureKustoEmulatorResource>` -- An `ApplicationModel.IResourceBuilder`1` for the [AzureKustoEmulatorResource](/reference/api/csharp/aspire.hosting.azure.kusto/azurekustoemulatorresource.md).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
