Skip to content

Commit 2981ee7

Browse files
committed
update: change file paths to use relative references in MongoDB tutorial
1 parent 7c4047e commit 2981ee7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

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

180-
:::code language="csharp" source="first-mongo-app/samples_snapshot/6.x/Book.cs":::
180+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples_snapshot/6.x/Book.cs":::
181181

182182
In the preceding class, the `Id` property is:
183183

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

192192
1. Add the following database configuration values to `appsettings.json`:
193193

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

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

198-
:::code language="csharp" source="first-mongo-app/samples/6.x/BookStoreApi/Models/BookStoreDatabaseSettings.cs":::
198+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/6.x/BookStoreApi/Models/BookStoreDatabaseSettings.cs":::
199199

200200
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.
201201

202202
1. Add the following highlighted code to `Program.cs`:
203203

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

206206
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`.
207207

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

210-
:::code language="csharp" source="first-mongo-app/samples/6.x/BookStoreApi/Program.cs" id="snippet_UsingModels":::
210+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/6.x/BookStoreApi/Program.cs" id="snippet_UsingModels":::
211211

212212
## Add a CRUD operations service
213213

214214
1. Add a *Services* directory to the project root.
215215
1. Add a `BooksService` class to the *Services* directory with the following code:
216216

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

219219
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.
220220

221221
1. Add the following highlighted code to `Program.cs`:
222222

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

225225
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.
226226

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

229-
:::code language="csharp" source="first-mongo-app/samples/6.x/BookStoreApi/Program.cs" id="snippet_UsingServices":::
229+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/6.x/BookStoreApi/Program.cs" id="snippet_UsingServices":::
230230

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

233233
* [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:
234234

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

237237
* [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:
238238

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

251251
Add a `BooksController` class to the *Controllers* directory with the following code:
252252

253-
:::code language="csharp" source="first-mongo-app/samples/6.x/BookStoreApi/Controllers/BooksController.cs":::
253+
:::code language="csharp" source="~/tutorials/first-mongo-app/samples/6.x/BookStoreApi/Controllers/BooksController.cs":::
254254

255255
The preceding web API controller:
256256

@@ -306,19 +306,19 @@ To satisfy the preceding requirements, make the following changes:
306306

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

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

311311
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`.
312312

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

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

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

319319
1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonProperty]` attribute reference:
320320

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

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

0 commit comments

Comments
 (0)