Skip to content

Commit 2dcb3da

Browse files
authored
Merge pull request #114551 from ealsur/users/ealsur/sqlapi2
Cosmos DB - MVC quickstart, order
2 parents 2b67c61 + cdae82d commit 2dcb3da

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

articles/cosmos-db/sql-api-dotnet-application.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: cosmos-db
66
ms.subservice: cosmosdb-sql
77
ms.devlang: dotnet
88
ms.topic: tutorial
9-
ms.date: 02/27/2020
9+
ms.date: 05/08/2020
1010
ms.author: sngun
1111
---
1212

@@ -184,15 +184,27 @@ First, we'll add a class that contains the logic to connect to and use Azure Cos
184184

185185
:::code language="csharp" source="~/samples-cosmosdb-dotnet-core-web-app/src/Services/ICosmosDbService.cs":::
186186

187-
1. Open the *Startup.cs* file in your solution and replace the `ConfigureServices` method with:
187+
1. Open the *Startup.cs* file in your solution and add the following method **InitializeCosmosClientInstanceAsync**, which reads the configuration and initializes the client.
188188

189-
:::code language="csharp" source="~/samples-cosmosdb-dotnet-core-web-app/src/Startup.cs" id="ConfigureServices":::
189+
:::code language="csharp" source="~/samples-cosmosdb-dotnet-core-web-app/src/Startup.cs" id="InitializeCosmosClientInstanceAsync" :::
190190

191-
The code in this step initializes the client based on the configuration as a singleton instance to be injected through [Dependency injection in ASP.NET Core](https://docs.microsoft.com/aspnet/core/fundamentals/dependency-injection).
191+
1. On that same file, replace the `ConfigureServices` method with:
192192

193-
1. Within the same file, add the following method **InitializeCosmosClientInstanceAsync**, which reads the configuration and initializes the client.
193+
:::code language="csharp" source="~/samples-cosmosdb-dotnet-core-web-app/src/Startup.cs" id="ConfigureServices":::
194+
195+
The code in this step initializes the client based on the configuration as a singleton instance to be injected through [Dependency injection in ASP.NET Core](https://docs.microsoft.com/aspnet/core/fundamentals/dependency-injection).
196+
197+
And make sure to change the default MVC Controller to `Item` by editing the routes in the `Configure` method of the same file:
198+
199+
```csharp
200+
app.UseEndpoints(endpoints =>
201+
{
202+
endpoints.MapControllerRoute(
203+
name: "default",
204+
pattern: "{controller=Item}/{action=Index}/{id?}");
205+
});
206+
```
194207

195-
[!code-csharp[](~/samples-cosmosdb-dotnet-core-web-app/src/Startup.cs?name=InitializeCosmosClientInstanceAsync)]
196208

197209
1. Define the configuration in the project's *appsettings.json* file as shown in the following snippet:
198210

0 commit comments

Comments
 (0)