Skip to content

Commit

Permalink
Fix CosmosDB README
Browse files Browse the repository at this point in the history
The extension method takes 2 strings: connection name and database name.

Fix dotnet#873
  • Loading branch information
eerhardt committed Jan 26, 2024
1 parent 6bc3591 commit 2d872c0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ dotnet add package Aspire.Microsoft.EntityFrameworkCore.Cosmos

## Usage example

In the _Program.cs_ file of your project, call the `AddCosmosDbContext` extension method to register a `DbContext` for use via the dependency injection container. The method takes a connection name parameter.
In the _Program.cs_ file of your project, call the `AddCosmosDbContext` extension method to register a `DbContext` for use via the dependency injection container. The method takes connection name and database name parameters.

```csharp
builder.AddCosmosDbContext<MyDbContext>("cosmosdb");
builder.AddCosmosDbContext<MyDbContext>("cosmosdb", "mydb");
```

You can then retrieve the `MyDbContext` instance using dependency injection. For example, to retrieve the context from a Web API controller:
Expand All @@ -44,7 +44,7 @@ The .NET Aspire Microsoft EntityFrameworkCore Cosmos component provides multiple
When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddCosmosDbContext()`:

```csharp
builder.AddCosmosDbContext<MyDbContext>("myConnection");
builder.AddCosmosDbContext<MyDbContext>("myConnection", "mydb");
```

And then the connection string will be retrieved from the `ConnectionStrings` configuration section:
Expand Down Expand Up @@ -83,7 +83,7 @@ The .NET Aspire Microsoft EntityFrameworkCore Cosmos component supports [Microso
Also you can pass the `Action<EntityFrameworkCoreCosmosDBSettings> configureSettings` delegate to set up some or all the options inline, for example to disable tracing from code:

```csharp
builder.AddCosmosDbContext<MyDbContext>("cosmosdb", settings => settings.Tracing = false);
builder.AddCosmosDbContext<MyDbContext>("cosmosdb", "mydb", settings => settings.Tracing = false);
```

## AppHost extensions
Expand All @@ -106,7 +106,7 @@ var myService = builder.AddProject<Projects.MyService>()
The `AddAzureCosmosDB` method will read connection information from the AppHost's configuration (for example, from "user secrets") under the `ConnectionStrings:cosmosdb` config key. The `WithReference` method passes that connection information into a connection string named `cosmosdb` in the `MyService` project. In the _Program.cs_ file of `MyService`, the connection can be consumed using:

```csharp
builder.AddCosmosDbContext<MyDbContext>("cosmosdb");
builder.AddCosmosDbContext<MyDbContext>("cosmosdb", "cosmosdb");
```

### Emulator usage
Expand Down

0 comments on commit 2d872c0

Please sign in to comment.