Skip to content

Commit bde56b3

Browse files
committed
correct v9 source paths
1 parent a803a31 commit bde56b3

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

aspnetcore/tutorials/first-mongo-app/includes/first-mongo-app9.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Use the previously installed MongoDB Shell in the following steps to create a da
165165
1. Add a *Models* directory to the project root.
166166
1. Add a `Book` class to the *Models* directory with the following code:
167167

168-
:::code language="csharp" source="first-mongo-app/samples_snapshot/9.x/Book.cs":::
168+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples_snapshot/9.x/Book.cs":::
169169

170170
In the preceding class, the `Id` property is:
171171

@@ -179,48 +179,48 @@ Use the previously installed MongoDB Shell in the following steps to create a da
179179

180180
1. Add the following database configuration values to `appsettings.json`:
181181

182-
:::code language="json" source="first-mongo-app/samples/9.x/BookStoreApi/appsettings.json" highlight="2-6":::
182+
:::code language="json" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/appsettings.json" highlight="2-6":::
183183

184184
1. Add a `BookStoreDatabaseSettings` class to the *Models* directory with the following code:
185185

186-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/BookStoreDatabaseSettings.cs":::
186+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Models/BookStoreDatabaseSettings.cs":::
187187

188188
The preceding `BookStoreDatabaseSettings` class is used to store the `appsettings.json` file's `BookStoreDatabase` property values. The JSON and C# property names are named identically to ease the mapping process.
189189

190190
1. Add the following highlighted code to `Program.cs`:
191191

192-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_BookStoreDatabaseSettings" highlight="4-5":::
192+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_BookStoreDatabaseSettings" highlight="4-5":::
193193

194194
In the preceding code, the configuration instance to which the `appsettings.json` file's `BookStoreDatabase` section binds is registered in the Dependency Injection (DI) container. For example, the `BookStoreDatabaseSettings` object's `ConnectionString` property is populated with the `BookStoreDatabase:ConnectionString` property in `appsettings.json`.
195195

196196
1. Add the following code to the top of `Program.cs` to resolve the `BookStoreDatabaseSettings` reference:
197197

198-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UsingModels":::
198+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UsingModels":::
199199

200200
## Add a CRUD operations service
201201

202202
1. Add a *Services* directory to the project root.
203203
1. Add a `BooksService` class to the *Services* directory with the following code:
204204

205-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Services/BooksService.cs" id="snippet_File":::
205+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Services/BooksService.cs" id="snippet_File":::
206206

207207
In the preceding code, a `BookStoreDatabaseSettings` instance is retrieved from DI via constructor injection. This technique provides access to the `appsettings.json` configuration values that were added in the [Add a configuration model](#add-a-configuration-model) section.
208208

209209
1. Add the following highlighted code to `Program.cs`:
210210

211-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_BooksService" highlight="7":::
211+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_BooksService" highlight="7":::
212212

213213
In the preceding code, the `BooksService` class is registered with DI to support constructor injection in consuming classes. The singleton service lifetime is most appropriate because `BooksService` takes a direct dependency on `MongoClient`. Per the official [Mongo Client reuse guidelines](https://mongodb.github.io/mongo-csharp-driver/2.14/reference/driver/connecting/#re-use), `MongoClient` should be registered in DI with a singleton service lifetime.
214214

215215
1. Add the following code to the top of `Program.cs` to resolve the `BooksService` reference:
216216

217-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UsingServices":::
217+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UsingServices":::
218218

219219
The `BooksService` class uses the following `MongoDB.Driver` members to run CRUD operations against the database:
220220

221221
* [MongoClient](https://mongodb.github.io/mongo-csharp-driver/2.14/apidocs/html/T_MongoDB_Driver_MongoClient.htm): Reads the server instance for running database operations. The constructor of this class is provided in the MongoDB connection string:
222222

223-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Services/BooksService.cs" id="snippet_ctor" highlight="4-5":::
223+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Services/BooksService.cs" id="snippet_ctor" highlight="4-5":::
224224

225225
* [IMongoDatabase](https://mongodb.github.io/mongo-csharp-driver/2.14/apidocs/html/T_MongoDB_Driver_IMongoDatabase.htm): Represents the Mongo database for running operations. This tutorial uses the generic [GetCollection\<TDocument>(collection)](https://mongodb.github.io/mongo-csharp-driver/2.14/apidocs/html/M_MongoDB_Driver_IMongoDatabase_GetCollection__1.htm) method on the interface to gain access to data in a specific collection. Run CRUD operations against the collection after this method is called. In the `GetCollection<TDocument>(collection)` method call:
226226

@@ -238,7 +238,7 @@ The `BooksService` class uses the following `MongoDB.Driver` members to run CRUD
238238

239239
Add a `BooksController` class to the *Controllers* directory with the following code:
240240

241-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Controllers/BooksController.cs":::
241+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Controllers/BooksController.cs":::
242242

243243
The preceding web API controller:
244244

@@ -257,19 +257,19 @@ To satisfy the preceding requirements, make the following changes:
257257

258258
1. In `Program.cs`, chain the following highlighted code on to the `AddControllers` method call:
259259

260-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_AddControllers" highlight="10-11":::
260+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_AddControllers" highlight="10-11":::
261261

262262
With the preceding change, property names in the web API's serialized JSON response match their corresponding property names in the CLR object type. For example, the `Book` class's `Author` property serializes as `Author` instead of `author`.
263263

264264
1. In `Models/Book.cs`, annotate the `BookName` property with the [`[JsonPropertyName]`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) attribute:
265265

266-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_BookName" highlight="2":::
266+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_BookName" highlight="2":::
267267

268268
The `[JsonPropertyName]` attribute's value of `Name` represents the property name in the web API's serialized JSON response.
269269

270270
1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonPropertyName]` attribute reference:
271271

272-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_UsingSystemTextJsonSerialization":::
272+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_UsingSystemTextJsonSerialization":::
273273

274274
1. Repeat the steps defined in the [Test the web API](#test-the-web-api) section. Notice the difference in JSON property names.
275275

@@ -428,7 +428,7 @@ Because our project is using OpenAPI, we only use the NSwag package to generate
428428

429429
In `Program.cs`, add the following highlighted code:
430430

431-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UseSwagger" highlight="6-9":::
431+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_UseSwagger" highlight="6-9":::
432432

433433
The previous code enables the Swagger middleware for serving the generated JSON document using the Swagger UI. Swagger is only enabled in a development environment. Enabling Swagger in a production environment could expose potentially sensitive details about the API's structure and implementation.
434434

0 commit comments

Comments
 (0)