From b8f4a0ca50a23c23ddb8b86549c930c5b9c34e95 Mon Sep 17 00:00:00 2001 From: Magnus Markling Date: Mon, 12 Dec 2022 03:57:34 +0100 Subject: [PATCH] improve tutorial (#1434) * fix indentation * Update 00_run_locally.md * simplify dotnet add * fix indentation * remove trailing space * clean up redis * already in solution root * k delete * clarify * Apply suggestions from code review Co-authored-by: David Fowler --- docs/tutorials/hello-tye/00_run_locally.md | 51 +++++++++++----------- docs/tutorials/hello-tye/02_add_redis.md | 20 +++++---- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/docs/tutorials/hello-tye/00_run_locally.md b/docs/tutorials/hello-tye/00_run_locally.md index bb0bb0ed..f2aff05f 100644 --- a/docs/tutorials/hello-tye/00_run_locally.md +++ b/docs/tutorials/hello-tye/00_run_locally.md @@ -92,33 +92,32 @@ Now that we have two applications running, let's make them communicate. By defau 3. Add a file `WeatherClient.cs` to the `frontend` project with the following contents: ```C# - using System.Text.Json; + using System.Text.Json; + using System.Net.Http.Json; - namespace frontend - { - public class WeatherClient - { - private readonly JsonSerializerOptions options = new JsonSerializerOptions() - { - PropertyNameCaseInsensitive = true, - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - }; - - private readonly HttpClient client; - - public WeatherClient(HttpClient client) - { - this.client = client; - } - - public async Task GetWeatherAsync() - { - var responseMessage = await this.client.GetAsync("/weatherforecast"); - var stream = await responseMessage.Content.ReadAsStreamAsync(); - return await JsonSerializer.DeserializeAsync(stream, options); - } - } - } + namespace frontend + { + public class WeatherClient + { + private readonly JsonSerializerOptions options = new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = true, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + }; + + private readonly HttpClient client; + + public WeatherClient(HttpClient client) + { + this.client = client; + } + + public async Task GetWeatherAsync() + { + return await this.client.GetFromJsonAsync("/weatherforecast"); + } + } + } ``` 4. Add a reference to the `Microsoft.Tye.Extensions.Configuration` package to the frontend project diff --git a/docs/tutorials/hello-tye/02_add_redis.md b/docs/tutorials/hello-tye/02_add_redis.md index ac871f69..221c0a94 100644 --- a/docs/tutorials/hello-tye/02_add_redis.md +++ b/docs/tutorials/hello-tye/02_add_redis.md @@ -52,12 +52,11 @@ We just showed how `tye` makes it easier to communicate between 2 applications r 2. Add a package reference to `Microsoft.Extensions.Caching.StackExchangeRedis` in the backend project: ``` - cd backend/ - dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis - cd .. + dotnet add backend/backend.csproj package Microsoft.Extensions.Caching.StackExchangeRedis ``` 3. Modify `Startup.ConfigureServices` in the `backend` project to add the redis `IDistributedCache` implementation. + ```C# public void ConfigureServices(IServiceCollection services) { @@ -66,7 +65,7 @@ We just showed how `tye` makes it easier to communicate between 2 applications r services.AddStackExchangeRedisCache(o => { o.Configuration = Configuration.GetConnectionString("redis"); - }); + }); } ``` The above configures redis to the configuration string for the `redis` service injected by the `tye` host. @@ -87,7 +86,7 @@ We just showed how `tye` makes it easier to communicate between 2 applications r image: redis bindings: - port: 6379 - connectionString: "${host}:${port}" + connectionString: "${host}:${port}" - name: redis-cli image: redis args: "redis-cli -h redis MONITOR" @@ -97,9 +96,7 @@ We just showed how `tye` makes it easier to communicate between 2 applications r > :bulb: The `"${host}:${port}"` format in the `connectionString` property will substitute the values of the host and port number to produce a connection string that can be used with StackExchange.Redis. -5. Run the `tye` command line in the solution root - - > :bulb: Make sure your command-line is in the `microservice/` directory. One of the previous steps had you change directories to edit a specific project. +5. Run the `tye run` command ``` tye run @@ -186,3 +183,10 @@ We just showed how `tye` makes it easier to communicate between 2 applications r 4. Clean-up At this point, you may want to undeploy the application by running `tye undeploy`. + + Also clean up the Redis deployment and service by running + + ```text + kubectl delete -f https://raw.githubusercontent.com/dotnet/tye/main/docs/tutorials/hello-tye/redis.yaml + ``` +