From 975fc162cc9be8267135b8f8e9130b498d49700c Mon Sep 17 00:00:00 2001 From: Stephen Walsh <868017+stphnwlsh@users.noreply.github.com> Date: Sat, 5 Dec 2026 14:01:30 +0000 Subject: [PATCH] Run dotnet run in the Development environment --- .agents/skills/configuration-and-environments/SKILL.md | 6 +++--- .agents/skills/presentation-integration-tests/SKILL.md | 2 +- .agents/skills/sample-data/SKILL.md | 2 +- .agents/skills/serilog/SKILL.md | 4 ++-- docs/RUN.md | 6 +++--- src/Presentation/Extensions/ProgramExtensions.cs | 4 ++-- src/Presentation/Presentation.http | 2 +- src/Presentation/Properties/launchSettings.json | 2 +- src/Presentation/Telemetry/TelemetrySettings.cs | 2 +- ...{appsettings.local.json => appsettings.Development.json} | 2 +- tests/Presentation.Tests.Integration/WebApiApplication.cs | 2 +- .../Telemetry/TelemetrySettingsTests.cs | 6 +++--- 12 files changed, 20 insertions(+), 20 deletions(-) rename src/Presentation/{appsettings.local.json => appsettings.Development.json} (87%) diff --git a/.agents/skills/configuration-and-environments/SKILL.md b/.agents/skills/configuration-and-environments/SKILL.md index 9bd1fae..f9bf0e4 100644 --- a/.agents/skills/configuration-and-environments/SKILL.md +++ b/.agents/skills/configuration-and-environments/SKILL.md @@ -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 --- @@ -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 | @@ -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 diff --git a/.agents/skills/presentation-integration-tests/SKILL.md b/.agents/skills/presentation-integration-tests/SKILL.md index be7ac5c..c750177 100644 --- a/.agents/skills/presentation-integration-tests/SKILL.md +++ b/.agents/skills/presentation-integration-tests/SKILL.md @@ -9,7 +9,7 @@ metadata: ## The rule -`tests/Presentation.Tests.Integration` makes real HTTP requests to the whole application in memory. `WebApiApplication` (a `WebApplicationFactory`) 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`) 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: diff --git a/.agents/skills/sample-data/SKILL.md b/.agents/skills/sample-data/SKILL.md index 614c449..bbba8e9 100644 --- a/.agents/skills/sample-data/SKILL.md +++ b/.agents/skills/sample-data/SKILL.md @@ -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 diff --git a/.agents/skills/serilog/SKILL.md b/.agents/skills/serilog/SKILL.md index b383ba2..3f72924 100644 --- a/.agents/skills/serilog/SKILL.md +++ b/.agents/skills/serilog/SKILL.md @@ -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`) | @@ -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: diff --git a/docs/RUN.md b/docs/RUN.md index 9d72ea0..d890193 100644 --- a/docs/RUN.md +++ b/docs/RUN.md @@ -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: @@ -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 on to . 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 on to . 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 diff --git a/src/Presentation/Extensions/ProgramExtensions.cs b/src/Presentation/Extensions/ProgramExtensions.cs index 6a59bbb..24a5901 100644 --- a/src/Presentation/Extensions/ProgramExtensions.cs +++ b/src/Presentation/Extensions/ProgramExtensions.cs @@ -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(); } diff --git a/src/Presentation/Presentation.http b/src/Presentation/Presentation.http index d2ed997..501180f 100644 --- a/src/Presentation/Presentation.http +++ b/src/Presentation/Presentation.http @@ -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 diff --git a/src/Presentation/Properties/launchSettings.json b/src/Presentation/Properties/launchSettings.json index 2e5ef63..8b411b1 100644 --- a/src/Presentation/Properties/launchSettings.json +++ b/src/Presentation/Properties/launchSettings.json @@ -8,7 +8,7 @@ "launchUrl": "scalar", "applicationUrl": "https://localhost:7341;http://localhost:7340", "environmentVariables": { - "DOTNET_ENVIRONMENT": "local" + "DOTNET_ENVIRONMENT": "Development" } } } diff --git a/src/Presentation/Telemetry/TelemetrySettings.cs b/src/Presentation/Telemetry/TelemetrySettings.cs index a1f6b08..7c23bcb 100644 --- a/src/Presentation/Telemetry/TelemetrySettings.cs +++ b/src/Presentation/Telemetry/TelemetrySettings.cs @@ -19,7 +19,7 @@ public class TelemetrySettings /// The service.version: the informational version from , the same one the version endpoint returns. public required string ServiceVersion { get; init; } - /// The deployment.environment.name, such as local or docker. + /// The deployment.environment.name, such as Development or docker. public required string EnvironmentName { get; init; } /// Where the OTLP exporters send everything. Empty means nothing is exported. diff --git a/src/Presentation/appsettings.local.json b/src/Presentation/appsettings.Development.json similarity index 87% rename from src/Presentation/appsettings.local.json rename to src/Presentation/appsettings.Development.json index 725216e..64287f9 100644 --- a/src/Presentation/appsettings.local.json +++ b/src/Presentation/appsettings.Development.json @@ -12,7 +12,7 @@ } ], "Properties": { - "ApplicationName": "CleanWebApi-Local" + "ApplicationName": "CleanWebApi-Development" } }, "Database": { diff --git a/tests/Presentation.Tests.Integration/WebApiApplication.cs b/tests/Presentation.Tests.Integration/WebApiApplication.cs index 19f49af..8723654 100644 --- a/tests/Presentation.Tests.Integration/WebApiApplication.cs +++ b/tests/Presentation.Tests.Integration/WebApiApplication.cs @@ -6,7 +6,7 @@ namespace CleanWebApi.Presentation.Tests.Integration; using Microsoft.Extensions.Hosting; internal sealed class WebApiApplication( - string environment = "local", + string environment = "Development", Dictionary? settings = null, Action? configureServices = null) : WebApplicationFactory { diff --git a/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs b/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs index 13e9e89..c84dde5 100644 --- a/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs +++ b/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs @@ -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] @@ -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");