From e1383c6399f4b33a12786321ee9f31d79582a842 Mon Sep 17 00:00:00 2001 From: David Pine Date: Mon, 1 Jul 2024 07:36:44 -0500 Subject: [PATCH] Add missing connection string sections. (#1170) * Add missing connection string sections. Fixes #1165 * Update docs/database/postgresql-entity-framework-component.md --- docs/database/azure-cosmos-db-component.md | 4 +-- .../mysql-entity-framework-component.md | 4 +-- .../oracle-entity-framework-component.md | 4 +-- docs/database/postgresql-component.md | 4 ++- .../postgresql-entity-framework-component.md | 26 +++++++++++++++-- docs/database/sql-server-component.md | 28 ++++++++++++++++--- .../sql-server-entity-framework-component.md | 24 +++++++++++++++- 7 files changed, 80 insertions(+), 14 deletions(-) diff --git a/docs/database/azure-cosmos-db-component.md b/docs/database/azure-cosmos-db-component.md index 2fc95d9e9..d44f42ca2 100644 --- a/docs/database/azure-cosmos-db-component.md +++ b/docs/database/azure-cosmos-db-component.md @@ -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 @@ -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/" } } ``` diff --git a/docs/database/mysql-entity-framework-component.md b/docs/database/mysql-entity-framework-component.md index d97b2b88d..2dead6bd4 100644 --- a/docs/database/mysql-entity-framework-component.md +++ b/docs/database/mysql-entity-framework-component.md @@ -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 @@ -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 diff --git a/docs/database/oracle-entity-framework-component.md b/docs/database/oracle-entity-framework-component.md index a4c449866..fcd77e632 100644 --- a/docs/database/oracle-entity-framework-component.md +++ b/docs/database/oracle-entity-framework-component.md @@ -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 @@ -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 diff --git a/docs/database/postgresql-component.md b/docs/database/postgresql-component.md index f74653455..a4542ee89 100644 --- a/docs/database/postgresql-component.md +++ b/docs/database/postgresql-component.md @@ -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 --- @@ -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 . It loads the 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: diff --git a/docs/database/postgresql-entity-framework-component.md b/docs/database/postgresql-entity-framework-component.md index e8f389c3d..c0bac5d55 100644 --- a/docs/database/postgresql-entity-framework-component.md +++ b/docs/database/postgresql-entity-framework-component.md @@ -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 @@ -82,6 +82,28 @@ var myService = builder.AddProject() 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("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 . It loads the 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. @@ -115,7 +137,7 @@ builder.AddNpgsqlDbContext( static settings => settings.ConnectionString = "YOUR_CONNECTIONSTRING"); ``` -### Configure multiple DBContext classes +### Configure multiple DbContext classes If you want to register more than one with different configuration, you can use `$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{typeof(TContext).Name}"` configuration section name. The json configuration would look like: diff --git a/docs/database/sql-server-component.md b/docs/database/sql-server-component.md index 20c02b7ec..d38329227 100644 --- a/docs/database/sql-server-component.md +++ b/docs/database/sql-server-component.md @@ -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 @@ -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 . 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. @@ -116,7 +136,7 @@ The following example shows an _:::no-loc text="appsettings.json":::_ file that You can also pass the `Action` 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); ``` @@ -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 diff --git a/docs/database/sql-server-entity-framework-component.md b/docs/database/sql-server-entity-framework-component.md index 1bee77328..555f83a65 100644 --- a/docs/database/sql-server-entity-framework-component.md +++ b/docs/database/sql-server-entity-framework-component.md @@ -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 @@ -74,6 +74,28 @@ var myService = builder.AddProject() 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()`: + +```csharp +builder.AddSqlServerDbContext("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 . It loads the 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.