Skip to content

Add missing connection string sections. #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/database/azure-cosmos-db-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire Azure Cosmos DB component
description: This article describes the .NET Aspire Azure Cosmos DB component features and capabilities.
ms.topic: how-to
ms.date: 06/05/2024
ms.date: 06/28/2024
---

# .NET Aspire Azure Cosmos DB component
Expand Down Expand Up @@ -114,7 +114,7 @@ The recommended connection approach is to use an account endpoint, which works w
```json
{
"ConnectionStrings": {
"cosmosConnectionName": "https://{account_name}.documents.azure.com:443/"
"cosmosConnectionName": "https://{account_name}.documents.azure.com:443/"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/database/mysql-entity-framework-component.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: MySQL Entity Framework Component
description: MySQL Entity Framework Component
ms.date: 06/05/2024
ms.date: 06/28/2024
---

# .NET Aspire Pomelo MySQL Entity Framework Component
Expand Down Expand Up @@ -94,7 +94,7 @@ And then the connection string will be retrieved from the `ConnectionStrings` co

The `EnrichMySqlDbContext` won't make use of the `ConnectionStrings` configuration section since it expects a `DbContext` to be registered at the point it is called.

See the [MySqlConnector documentation](https://mysqlconnector.net/connection-options/) for more information on how to format this connection string.
For more information, see the [MySqlConnector documentation](https://mysqlconnector.net/connection-options/).

### Use configuration providers

Expand Down
4 changes: 2 additions & 2 deletions docs/database/oracle-entity-framework-component.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Oracle Entity Framework Component
description: Oracle Entity Framework Component
ms.date: 06/03/2024
ms.date: 06/28/2024
---

# .NET Aspire Oracle Entity Framework Component
Expand Down Expand Up @@ -126,7 +126,7 @@ And then the connection string will be retrieved from the `ConnectionStrings` co

The `EnrichOracleDatabaseDbContext` won't make use of the `ConnectionStrings` configuration section since it expects a `DbContext` to be registered at the point it is called.

See the [ODP.NET documentation](https://www.oracle.com/database/technologies/appdev/dotnet/odp.html) for more information on how to format this connection string.
For more information, see the [ODP.NET documentation](https://www.oracle.com/database/technologies/appdev/dotnet/odp.html).

### Use configuration providers

Expand Down
4 changes: 3 additions & 1 deletion docs/database/postgresql-component.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: .NET Aspire PostgreSQL component
description: This article describes the .NET Aspire PostgreSQL component.
ms.date: 06/05/2024
ms.date: 06/28/2024
ms.topic: how-to
---

Expand Down Expand Up @@ -86,6 +86,8 @@ And then the connection string will be retrieved from the `ConnectionStrings` co
}
```

For more information, see the [ConnectionString](https://www.npgsql.org/doc/connection-string-parameters.html).

### Use configuration providers

The .NET Aspire PostgreSQL component supports <xref:Microsoft.Extensions.Configuration?displayProperty=fullName>. It loads the <xref:Aspire.Npgsql.NpgsqlSettings> from _:::no-loc text="appsettings.json":::_ or other configuration files by using the `Aspire:Npgsql` key. Example _:::no-loc text="appsettings.json":::_ that configures some of the options:
Expand Down
26 changes: 24 additions & 2 deletions docs/database/postgresql-entity-framework-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire PostgreSQL Entity Framework Core component
description: This article describes the .NET Aspire PostgreSQL Entity Framework Core component.
ms.topic: how-to
ms.date: 06/05/2024
ms.date: 06/28/2024
---

# .NET Aspire PostgreSQL Entity Framework Core component
Expand Down Expand Up @@ -82,6 +82,28 @@ var myService = builder.AddProject<Projects.MyService>()

The .NET Aspire PostgreSQL Entity Framework Core component provides multiple configuration approaches and options to meet the requirements and conventions of your project.

### Use a connection string

When using a connection string from the `ConnectionStrings` configuration section, you provide the name of the connection string when calling `AddNpgsqlDbContext`:

```csharp
builder.AddNpgsqlDbContext<MyDbContext>("myConnection");
```

The connection string is retrieved from the `ConnectionStrings` configuration section:

```json
{
"ConnectionStrings": {
"myConnection": "Host=myserver;Database=test"
}
}
```

The `EnrichNpgsqlDbContext` won't make use of the `ConnectionStrings` configuration section since it expects a `DbContext` to be registered at the point it is called.

For more information, see the [ConnectionString](https://www.npgsql.org/doc/connection-string-parameters.html).

### Use configuration providers

The .NET Aspire PostgreSQL Entity Framework Core component supports <xref:Microsoft.Extensions.Configuration?displayProperty=fullName>. It loads the <xref:Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.NpgsqlEntityFrameworkCorePostgreSQLSettings> from configuration files such as _:::no-loc text="appsettings.json":::_ by using the `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL` key. If you have set up your configurations in the `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL` section you can just call the method without passing any parameter.
Expand Down Expand Up @@ -115,7 +137,7 @@ builder.AddNpgsqlDbContext<YourDbContext>(
static settings => settings.ConnectionString = "YOUR_CONNECTIONSTRING");
```

### Configure multiple DBContext classes
### Configure multiple DdContext classes

If you want to register more than one <xref:Microsoft.EntityFrameworkCore.DbContext> with different configuration, you can use `$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{typeof(TContext).Name}"` configuration section name. The json configuration would look like:

Expand Down
28 changes: 24 additions & 4 deletions docs/database/sql-server-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire SQL Server component
description: This article describes the .NET Aspire SQL Server component.
ms.topic: how-to
ms.date: 06/05/2024
ms.date: 06/28/2024
---

# .NET Aspire SQL Server component
Expand Down Expand Up @@ -91,6 +91,26 @@ For more information, see [External parameters](../fundamentals/external-paramet

The .NET Aspire SQL Server component provides multiple configuration approaches and options to meet the requirements and conventions of your project.

### Use a connection string

When using a connection string from the `ConnectionStrings` configuration section, you provide the name of the connection string when calling `AddSqlServerClient`:

```csharp
builder.AddSqlServerClient("myConnection");
```

The connection string is retrieved from the `ConnectionStrings` configuration section:

```json
{
"ConnectionStrings": {
"myConnection": "Data Source=myserver;Initial Catalog=master"
}
}
```

For more information, see the [ConnectionString](/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring#remarks).

### Use configuration providers

The .NET Aspire SQL Server supports <xref:Microsoft.Extensions.Configuration?displayProperty=fullName>. It loads the `MicrosoftDataSqlClientSettings` from configuration files such as _:::no-loc text="appsettings.json":::_ by using the `Aspire:SqlServer:SqlClient` key. If you have set up your configurations in the `Aspire:SqlServer:SqlClient` section, you can just call the method without passing any parameter.
Expand All @@ -116,7 +136,7 @@ The following example shows an _:::no-loc text="appsettings.json":::_ file that
You can also pass the `Action<MicrosoftDataSqlClientSettings>` delegate to set up some or all the options inline, for example to turn off the `DisableMetrics`:

```csharp
builder.AddSqlServerSqlClientConfig(
builder.AddSqlServerClient(
static settings => settings.DisableMetrics = true);
```

Expand All @@ -139,10 +159,10 @@ If you want to add more than one `SqlConnection` you could use named instances.
}
```

To load the named configuration section from the json config call the `AddSqlServerSqlClientConfig` method by passing the `INSTANCE_NAME`.
To load the named configuration section from the json config call the `AddSqlServerClient` method by passing the `INSTANCE_NAME`.

```csharp
builder.AddSqlServerSqlClientConfig("INSTANCE_NAME");
builder.AddSqlServerClient("INSTANCE_NAME");
```

### Configuration options
Expand Down
24 changes: 23 additions & 1 deletion docs/database/sql-server-entity-framework-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire SqlServer Entity Framework Core component
description: This article describes the .NET Aspire SQL Server Entity Framework Core component.
ms.topic: how-to
ms.date: 06/05/2024
ms.date: 06/28/2024
---

# .NET Aspire SqlServer Entity Framework Core component
Expand Down Expand Up @@ -74,6 +74,28 @@ var myService = builder.AddProject<Projects.MyService>()

The .NET Aspire SQL Server Entity Framework Core component provides multiple configuration approaches and options to meet the requirements and conventions of your project.

### Use connection string

When using a connection string from the `ConnectionStrings` configuration section, you provide the name of the connection string when calling `builder.AddSqlServerDbContext<TContext>()`:

```csharp
builder.AddSqlServerDbContext<MyDbContext>("myConnection");
```

The connection string is retrieved from the `ConnectionStrings` configuration section:

```json
{
"ConnectionStrings": {
"myConnection": "Data Source=myserver;Initial Catalog=master"
}
}
```

The `EnrichSqlServerDbContext` won't make use of the `ConnectionStrings` configuration section since it expects a `DbContext` to be registered at the point it's called.

For more information, see the [ConnectionString](/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring#remarks).

### Use configuration providers

The .NET Aspire SQL Server Entity Framework Core component supports <xref:Microsoft.Extensions.Configuration?displayProperty=fullName>. It loads the <xref:Aspire.Microsoft.EntityFrameworkCore.SqlServer.MicrosoftEntityFrameworkCoreSqlServerSettings> from configuration files such as _:::no-loc text="appsettings.json":::_ by using the `Aspire:Microsoft:EntityFrameworkCore:SqlServer` key. If you have set up your configurations in the `Aspire:Microsoft:EntityFrameworkCore:SqlServer` section you can just call the method without passing any parameter.
Expand Down
Loading