# TraconPostgreSqlBuilderExtensions

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.traconpostgresqlbuilderextensions/
> Summary: TraconPostgreSqlBuilderExtensions: Extensions that add PostgreSQL persistence to the Tracon chain.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.PostgreSql.dll</code></div>

Extensions that add PostgreSQL persistence to the Tracon chain.

```csharp
public static class TraconPostgreSqlBuilderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.traconpostgresqlbuilderextensions/">TraconPostgreSqlBuilderExtensions</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Methods

### <a id="Tracon_TraconPostgreSqlBuilderExtensions_UsePostgreSql_Tracon_ITraconBuilder_System_String_"></a> UsePostgreSql\(ITraconBuilder, string\)

Enables PostgreSQL persistence given a connection string.

```csharp
public static ITraconBuilder UsePostgreSql(this ITraconBuilder builder, string connectionString)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`connectionString` [string](https://learn.microsoft.com/dotnet/api/system.string)

The PostgreSQL connection string.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

The schema is created and migrated at startup; no separate migration
step is needed.

```csharp
builder.AddTracon()
       .UseOpenAI(builder.Configuration["OpenAI:ApiKey"]!)
       .UsePostgreSql(builder.Configuration.GetConnectionString("Tracon")!);
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`connectionString` is empty.

### <a id="Tracon_TraconPostgreSqlBuilderExtensions_UsePostgreSql_Tracon_ITraconBuilder_Microsoft_Extensions_Configuration_IConfiguration_"></a> UsePostgreSql\(ITraconBuilder, IConfiguration\)

Enables PostgreSQL persistence, reading settings from the `Tracon:PostgreSql` section.

```csharp
public static ITraconBuilder UsePostgreSql(this ITraconBuilder builder, IConfiguration configurationSection)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configurationSection` [IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)

The section settings are read from. Usually
`configuration.GetSection(TraconPostgreSqlOptions.SectionName)`.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### <a id="Tracon_TraconPostgreSqlBuilderExtensions_UsePostgreSql_Tracon_ITraconBuilder_System_Action_Tracon_TraconPostgreSqlOptions__"></a> UsePostgreSql\(ITraconBuilder, Action<TraconPostgreSqlOptions\>\)

Enables PostgreSQL persistence with settings given in code.

```csharp
public static ITraconBuilder UsePostgreSql(this ITraconBuilder builder, Action<TraconPostgreSqlOptions> configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[TraconPostgreSqlOptions](/api/tracon.traconpostgresqloptions/)\>

The settings mutator.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

Stores are registered with `ServiceCollectionDescriptorExtensions.Replace`,
not `TryAdd`. `AddTracon` has already registered the
in-memory stores with `TryAddSingleton` and runs *before* this
call in the chain; using `TryAdd` here would silently do nothing.

Overwriting is correct here because `UsePostgreSql` is the
consumer's **explicit** choice. The "register with TryAdd"
rule is for Tracon's defaults, not for explicit calls.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
