Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .agents/skills/configuration-and-environments/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: configuration-and-environments
description: How settings are layered with appsettings files and environment variables, what the local and docker environments are, and how to add a new setting. Use when adding configuration, a connection string or environment-specific behaviour.
description: How settings are layered with appsettings files and environment variables, what the Development and docker environments are, and how to add a new setting. Use when adding configuration, a connection string or environment-specific behaviour.
metadata:
scope: shared
---
Expand All @@ -15,7 +15,7 @@ The Lambda template has no appsettings files or environments. Its startup builds

| Environment | Set by | Used for |
| --- | --- | --- |
| `local` | `launchSettings.json` (`DOTNET_ENVIRONMENT=local`) | `dotnet run` on a developer machine: console logs, sample data on |
| `Development` | `launchSettings.json` (`DOTNET_ENVIRONMENT=Development`) | `dotnet run` on a developer machine: console logs, sample data on |
| `docker` | `docker-compose.yml` and the Dockerfile | `docker compose up`: telemetry over OTLP through the collector to the Aspire dashboard, database in `/app/data`, sample data on |
| anything else | the host | Real deployments: base settings only, sample data off, HSTS on |

Expand All @@ -39,7 +39,7 @@ Settings that exist today:
## Don't

- Put secrets, passwords or tokens in any `appsettings*.json` file. Use environment variables or user secrets.
- Check `IsEnvironment("local")` for behaviour that should be a setting. Add a setting instead.
- Check `IsDevelopment()` or `IsEnvironment("docker")` for behaviour that should be a setting. Add a setting instead.
- Read `Environment.GetEnvironmentVariable` directly. Go through `IConfiguration`.

## Check
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/presentation-integration-tests/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:

## The rule

`tests/Presentation.Tests.Integration` makes real HTTP requests to the whole application in memory. `WebApiApplication` (a `WebApplicationFactory<Program>`) starts the app with the `local` environment, its own shared-cache in-memory SQLite database and the sample data on, so tests never touch a file or each other.
`tests/Presentation.Tests.Integration` makes real HTTP requests to the whole application in memory. `WebApiApplication` (a `WebApplicationFactory<Program>`) starts the app with the `Development` environment, its own shared-cache in-memory SQLite database and the sample data on, so tests never touch a file or each other.

Each test class creates one `WebApiApplication` in its constructor and disposes it. The constructor takes three optional arguments:

Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/sample-data/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are two kinds of data, and they never mix.
| Sample data | `src/Infrastructure/Databases/MovieReviews/Extensions/MovieReviewsDbContextExtensions.cs` (`AddData`) | Local runs, Docker and the presentation integration tests | 15 authors, 50 movies, 150 reviews from Bogus with a fixed seed |
| Test data | `tests/Infrastructure.Tests.Integration/Databases/MovieReviews/Extensions/MovieReviewsCollectionData.cs` (`AddTestData`) | Repository tests | A handful of hand-written rows named "One", "Two", "Three" so assertions can find them |

Sample data is only added when `Database:SeedSampleData` is `true` (on in `appsettings.local.json` and `appsettings.docker.json`, off in `appsettings.json`; Lambda turns it on only in `docker-compose.yml`) and the database is empty. A deployed copy never starts with fake data.
Sample data is only added when `Database:SeedSampleData` is `true` (on in `appsettings.Development.json` and `appsettings.docker.json`, off in `appsettings.json`; Lambda turns it on only in `docker-compose.yml`) and the database is empty. A deployed copy never starts with fake data.

## Steps

Expand Down
4 changes: 2 additions & 2 deletions .agents/skills/serilog/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Serilog is the logger. Application and Infrastructure code log through `Microsof

| Environment | Sink | Where to look |
| --- | --- | --- |
| `local` | Console, with the output template in `appsettings.local.json` | The terminal |
| `Development` | Console, with the output template in `appsettings.Development.json` | The terminal |
| `docker` | Console, and OTLP through the collector to the Aspire dashboard | The Aspire dashboard, on the port `docs/RUN.md` lists, or `docker compose logs` |
| Lambda, anywhere | Console, as compact JSON, and OTLP when the endpoint is set | CloudWatch Logs, or `docker compose logs` for the emulator, and the Aspire dashboard in Docker Compose |
| Any, when `OTEL_EXPORTER_OTLP_ENDPOINT` is set | Also OTLP, through `Serilog.Sinks.OpenTelemetry` | Whatever receives the OTLP (`telemetry`) |
Expand All @@ -29,7 +29,7 @@ Every event carries these properties:
| `AssemblyVersion`, `AssemblyInformationalVersion` | Added in code at startup |
| Anything pushed with `LogContext` | `FromLogContext` |

Levels are set in configuration, never in code: `Information` by default and `Debug` in `local`, with `Information` for `Microsoft`, `Warning` for `Microsoft.AspNetCore` and `Microsoft.EntityFrameworkCore.Database.Command` (a line per SQL statement buries everything else, and EF Core's meter already counts them), and `Error` for `System`. The built-in `Logging` section is set to `None` so nothing is written twice.
Levels are set in configuration, never in code: `Information` by default and `Debug` in `Development`, with `Information` for `Microsoft`, `Warning` for `Microsoft.AspNetCore` and `Microsoft.EntityFrameworkCore.Database.Command` (a line per SQL statement buries everything else, and EF Core's meter already counts them), and `Error` for `System`. The built-in `Logging` section is set to `None` so nothing is written twice.

Three things log a request, and each says something the others don't:

Expand Down
6 changes: 3 additions & 3 deletions docs/RUN.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Running Clean Web API

There are two pre-configured environments, `local` and `docker`. Logs go to the console in both. Traces, metrics and logs also leave over OTLP whenever `OTEL_EXPORTER_OTLP_ENDPOINT` is set, which Docker Compose does for you.
There are two pre-configured environments, `Development` and `docker`. Logs go to the console in both. Traces, metrics and logs also leave over OTLP whenever `OTEL_EXPORTER_OTLP_ENDPOINT` is set, which Docker Compose does for you.

## Database

The app stores its data in a SQLite file, `movie-reviews.db`, next to the app. In Docker the file is `/app/data/movie-reviews.db`, on the `movie-reviews-data` volume, so it survives a restart. On startup the app applies any pending Entity Framework Core migrations. When `Database:SeedSampleData` is `true`, it also seeds the same sample data into an empty database. It's on in `appsettings.local.json` and `appsettings.docker.json` and off everywhere else, so a deployed copy never starts with fake data. Delete the file, or run `docker compose down -v`, to start again. Change `ConnectionStrings:MovieReviews` to point somewhere else, or to `Data Source=MovieReviews;Mode=Memory;Cache=Shared` to keep everything in memory.
The app stores its data in a SQLite file, `movie-reviews.db`, next to the app. In Docker the file is `/app/data/movie-reviews.db`, on the `movie-reviews-data` volume, so it survives a restart. On startup the app applies any pending Entity Framework Core migrations. When `Database:SeedSampleData` is `true`, it also seeds the same sample data into an empty database. It's on in `appsettings.Development.json` and `appsettings.docker.json` and off everywhere else, so a deployed copy never starts with fake data. Delete the file, or run `docker compose down -v`, to start again. Change `ConnectionStrings:MovieReviews` to point somewhere else, or to `Data Source=MovieReviews;Mode=Memory;Cache=Shared` to keep everything in memory.

To add a migration after changing the data model:

Expand Down Expand Up @@ -75,7 +75,7 @@ Every span, metric and log carries `service.version`, so you can always tell whi

## HTTPS

The app redirects HTTP to HTTPS whenever it has an HTTPS port, which is why `dotnet run` sends <http://localhost:7340> on to <https://localhost:7341>. Outside the `local` and `Development` environments it also sends an HSTS header. The container only listens on HTTP, so in production put it behind a proxy or load balancer that ends TLS, and set `ASPNETCORE_FORWARDEDHEADERS_ENABLED=true` so the app knows the original request was HTTPS.
The app redirects HTTP to HTTPS whenever it has an HTTPS port, which is why `dotnet run` sends <http://localhost:7340> on to <https://localhost:7341>. Outside the `Development` environment it also sends an HSTS header. The container only listens on HTTP, so in production put it behind a proxy or load balancer that ends TLS, and set `ASPNETCORE_FORWARDEDHEADERS_ENABLED=true` so the app knows the original request was HTTPS.

## Tests

Expand Down
4 changes: 2 additions & 2 deletions src/Presentation/Extensions/ProgramExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public static WebApplication ConfigureApplication(this WebApplication app)

_ = app.UseSecurityHeaders();

// HSTS tells browsers to only use HTTPS from then on, so it's left off for local runs.
if (!app.Environment.IsDevelopment() && !app.Environment.IsEnvironment("local"))
// HSTS tells browsers to only use HTTPS from then on, so it's left off in Development.
if (!app.Environment.IsDevelopment())
{
_ = app.UseHsts();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/Presentation.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@host = https://localhost:7341
# @host = http://localhost:7340

# Sample data ids from the fixed local and docker seed.
# Sample data ids from the fixed Development and docker seed.
@movieId = cb188ef6-14e7-f85f-2f78-924c2ab26b28
@authorId = 01fa8b58-05d2-abd4-e55c-2633222dd0a5
@reviewId = 45911e6f-a366-417b-1453-f34097338ee2
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"launchUrl": "scalar",
"applicationUrl": "https://localhost:7341;http://localhost:7340",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "local"
"DOTNET_ENVIRONMENT": "Development"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/Telemetry/TelemetrySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TelemetrySettings
/// <summary>The <c>service.version</c>: the informational version from <see cref="VersionInfo"/>, the same one the version endpoint returns.</summary>
public required string ServiceVersion { get; init; }

/// <summary>The <c>deployment.environment.name</c>, such as <c>local</c> or <c>docker</c>.</summary>
/// <summary>The <c>deployment.environment.name</c>, such as <c>Development</c> or <c>docker</c>.</summary>
public required string EnvironmentName { get; init; }

/// <summary>Where the OTLP exporters send everything. Empty means nothing is exported.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"Properties": {
"ApplicationName": "CleanWebApi-Local"
"ApplicationName": "CleanWebApi-Development"
}
},
"Database": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CleanWebApi.Presentation.Tests.Integration;
using Microsoft.Extensions.Hosting;

internal sealed class WebApiApplication(
string environment = "local",
string environment = "Development",
Dictionary<string, string?>? settings = null,
Action<IServiceCollection>? configureServices = null) : WebApplicationFactory<Program>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public void FromConfiguration_ShouldReturn_DisabledDefaults_WhenNothingIsSet()
var version = new VersionInfo { FileVersion = "1.2.3.0", InformationalVersion = "1.2.3+e30eba8" };

// Act
var result = TelemetrySettings.FromConfiguration(configuration, "local", version);
var result = TelemetrySettings.FromConfiguration(configuration, "Development", version);

// Assert
result.Enabled.ShouldBeFalse();
result.ServiceName.ShouldBe(TelemetrySettings.DefaultServiceName);
result.ServiceVersion.ShouldBe("1.2.3+e30eba8");
result.EnvironmentName.ShouldBe("local");
result.EnvironmentName.ShouldBe("Development");
}

[Fact]
Expand Down Expand Up @@ -56,7 +56,7 @@ public void FromConfiguration_ShouldReturn_UnknownVersion_WhenVersionIsEmpty()
var version = VersionInfo.FromAssembly(null);

// Act
var result = TelemetrySettings.FromConfiguration(configuration, "local", version);
var result = TelemetrySettings.FromConfiguration(configuration, "Development", version);

// Assert
result.ServiceVersion.ShouldBe("unknown");
Expand Down
Loading