### Install Just (Prerequisites) Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Installs the 'just' command-line tool, often used for running project-specific commands, as a prerequisite for the project. ```bash cargo install just ``` -------------------------------- ### Install .NET Report Generator Global Tool Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/counter-api-tests/README.md Installs the `dotnet-reportgenerator-globaltool` globally, which is essential for generating comprehensive code coverage reports from test results. ```powershell dotnet tool install -g dotnet-reportgenerator-globaltool ``` -------------------------------- ### Prepare and Run Project with Makefile Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Creates an empty '.env' file and then executes the 'run' target defined in the project's Makefile, typically used for starting the application on Ubuntu. ```sh touch .env ``` ```sh make run ``` -------------------------------- ### Run Project with Justfile Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Executes the default 'run' command defined in the project's Justfile, providing a cross-platform way to start the application. ```sh just run ``` -------------------------------- ### Install Aspirate Tool for Kubernetes Deployment Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Installs the 'aspirate' .NET global tool, which is used for deploying .NET Aspire applications to Kubernetes, including prerelease versions. ```sh dotnet tool install -g aspirate --prerelease ``` -------------------------------- ### Open Generated Code Coverage Report Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/counter-api-tests/README.md Opens the generated HTML code coverage report in the default web browser. This allows for immediate viewing and analysis of the project's code coverage statistics. ```powershell .\coverage\index.htm ``` -------------------------------- ### Run .NET Tests with Custom Settings Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/counter-api-tests/README.md Executes .NET tests across the project, applying configurations defined in the `tests.runsettings` file. This allows for customized test execution, data collection, and other specific settings. ```powershell dotnet test --settings tests.runsettings ``` -------------------------------- ### Submit HTTP Request with Custom Trace Header (JSON) Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/Custom-trace‐id-in-YARP This JSON snippet demonstrates how to construct an HTTP GET request using a tool like REST Client or Postman, including a custom 'trace-id' header. The `{{$guid}}` placeholder indicates that a unique GUID should be generated and used as the trace identifier for the request, allowing for end-to-end tracing. ```json ### GET http://{{hostname}}/p/api/v1/item-types content-type: application/json trace-id: "{{$guid}}" ``` -------------------------------- ### Generate HTML Code Coverage Report Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/counter-api-tests/README.md Generates an HTML code coverage report by processing Cobertura XML files found within the test results directories. The output report is saved into a 'coverage' folder for easy access and review. ```powershell reportgenerator ` -reports:".\**\TestResults\**\coverage.cobertura.xml" ` -targetdir:"coverage" ` -reporttypes:Html ``` -------------------------------- ### Configure YARP for Trace-ID Transformation in C# Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/Custom-trace‐id-in-YARP This C# code snippet configures YARP (Yet Another Reverse Proxy) within a .NET Aspire application to intercept and transform the 'trace-id' header. It parses the incoming 'trace-id', generates a new GUID if invalid, and replaces the trace-ID segment within the 'traceparent' header to ensure consistent tracing across services. This is particularly useful for distributed tracing scenarios. ```csharp builder.Services.AddReverseProxy() .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")) .AddTransforms(b => { // todo: only for testing purposes, remove later // https://stackoverflow.com/questions/70306118/set-traceid-on-activity b.AddRequestTransform(async transformContext => { var context = transformContext.HttpContext; var traceIdFromProxy = context.Request.Headers["trace-id"].FirstOrDefault()?.Trim('"'); if (Guid.TryParse(traceIdFromProxy, out var parsedGuid)) { traceIdFromProxy = parsedGuid.ToString("N"); } else { // Handle the case where the traceId is not a valid GUID traceIdFromProxy = Guid.NewGuid().ToString("N"); } if (context.Request.Headers.TryGetValue("traceparent", out var traceParent)) { if (context.Request.Headers.Remove("traceparent")) { var traceParentReplaced = Regex.Replace(traceParent, "-.*?-|", $"-${traceIdFromProxy}-"); Activity.Current = new Activity("Yarp.ReverseProxy") .SetParentId(traceParentReplaced) .Start(); } } await ValueTask.CompletedTask; }); }) .AddServiceDiscoveryDestinationResolver(); ``` -------------------------------- ### Publish .NET Aspire Product API to Container Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Publishes the .NET Aspire product API project to a container image, configuring it for single-file, self-contained deployment for Linux x64, and specifying container registry details. ```sh dotnet publish "/workspaces/coffeeshop-aspire/app-host/../product-api/CoffeeShop.ProductApi.csproj" -p:PublishProfile="DefaultContainer" -p:PublishSingleFile="true" -p:PublishTrimmed="false" --self-contained "true" --verbosity "quiet" --nologo -r "linux-x64" -p:ContainerRegistry="k3d-myregistry.localhost:12345" -p:ContainerRepository="product-api" -p:ContainerImageTag="latest" ``` -------------------------------- ### Run .NET Aspire Coffeeshop Application Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/README.md Instructions to build and run the .NET Aspire Coffeeshop application from the command line, including the default local URL. ```sh dotnet build coffeeshop-aspire.sln dotnet run --project app-host/CoffeeShop.AppHost.csproj # http://localhost:5019 ``` -------------------------------- ### Generate .NET Aspire Manifest File Source: https://github.com/thangchung/practical-dotnet-aspire/wiki/.NET-Aspire-‐-deployment Generates a .NET Aspire manifest JSON file from the application host project, specifying the output path for the manifest. ```sh dotnet run --project app-host\CoffeeShop.AppHost.csproj \ --publisher manifest \ --output-path ../aspire-manifest.json ``` -------------------------------- ### C4 Model: System Context Diagram for CoffeeShop Application Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/README.md A C4 Model diagram illustrating the high-level system context of the CoffeeShop application, showing the main boundaries and interactions between customers, the application, database, and message queue. ```mermaid C4Context title System Context diagram for CoffeeShop Application Boundary(b0, "Boundary1") { Person(customer, "Customers", "Customers of the coffeeshop.") Boundary(b1, "Application", "boundary") { System(SystemA, "CoffeeShop app", "Allows customers to submit and view their orders.") } Boundary(b2, "Infrastructure", "boundary") { SystemDb(SystemD, "Database", "A system of the coffeeshop app.") SystemQueue(SystemQ, "Message Queue", "A system of the coffeeshop app.") } } Rel(customer, SystemA, "Uses") Rel(SystemA, SystemD, "Uses") Rel(SystemA, SystemQ, "Uses") ``` -------------------------------- ### C4 Model: Container Diagram for CoffeeShop Application Source: https://github.com/thangchung/practical-dotnet-aspire/blob/main/README.md A C4 Model diagram detailing the internal structure of the CoffeeShop application, showing individual containers like the Gateway, various microservices (Counter, Barista, Kitchen, Product, Order Summary), Database, and Message Broker, along with their communication protocols. ```mermaid C4Container title Container diagram for CoffeeShop Application Person(customer, "Customers", "Customers of the coffeeshop.") Container_Boundary(c1, "CoffeeShop Application") { Container(reverse_proxy, "Gateway", "C#, .NET 8, YARP", "The reverse proxy/API gateway of the coffeeshop app.") Container(counter_api, "Counter APIs", "C#, .NET 8, MassTransit", "The counter service.") Container(barista_api, "Barista APIs", "C#, .NET 8, MassTransit", "The barista service.") Container(kitchen_api, "Kitchen APIs", "C#, .NET 8, MassTransit", "The kitchen service.") Container(order_summary, "Order Summary", "C#, .NET 8, Marten", "The order summary service.") Container(product_api, "Product APIs", "C#, .NET 8", "The product service.") Boundary(b1, "Docker containers", "boundary") { ContainerDb(database, "Database", "Postgres", "Stores orders, audit logs, etc.") ContainerQueue(message_broker, "Message Broker", "RabbitMQ", "Asynchronous communication between counter, barista, kitchen, and order-summary") } } Rel(customer, reverse_proxy, "Uses", "HTTPS") Rel(reverse_proxy, product_api, "Proxies", "HTTP") Rel(reverse_proxy, counter_api, "Proxies", "HTTP") Rel(order_summary, database, "Uses", "TCP") Rel(counter_api, product_api, "Calls", "HTTP") Rel(counter_api, message_broker, "Publishes", "TCP") Rel(counter_api, message_broker, "Publishes", "TCP") Rel_Back(barista_api, message_broker, "Subscribes", "TCP") Rel_Back(kitchen_api, message_broker, "Subscribes", "TCP") Rel_Back(order_summary, message_broker, "Subscribes", "TCP") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.