Browse Source

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 <davidfowl@gmail.com>
pull/1487/head
Magnus Markling 4 years ago
committed by GitHub
parent
commit
b8f4a0ca50
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      docs/tutorials/hello-tye/00_run_locally.md
  2. 20
      docs/tutorials/hello-tye/02_add_redis.md

51
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<WeatherForecast[]> GetWeatherAsync()
{
var responseMessage = await this.client.GetAsync("/weatherforecast");
var stream = await responseMessage.Content.ReadAsStreamAsync();
return await JsonSerializer.DeserializeAsync<WeatherForecast[]>(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<WeatherForecast[]> GetWeatherAsync()
{
return await this.client.GetFromJsonAsync<WeatherForecast[]>("/weatherforecast");
}
}
}
```
4. Add a reference to the `Microsoft.Tye.Extensions.Configuration` package to the frontend project

20
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
```

Loading…
Cancel
Save