Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Lessons I Learned from Using Aspire in Produ...

Oleksii Nikiforov
October 16, 2024
240

10 Lessons I Learned from Using Aspire in Production

I have been using .NET Aspire for a while now and have learned a lot along the way. In this blog post, I will share some of the lessons I have learned from using .NET Aspire in production.

https://nikiforovall.github.io/dotnet/aspire/2024/09/30/aspire-lessons-learned.html

Oleksii Nikiforov

October 16, 2024
Tweet

Transcript

  1. Build anything with a unified platform .NET Cloud Web Desktop

    Mobile Gaming IoT AI Tools Visual Studio Code CLI Visual Studio Operating system Linux Windows macOS + Ecosystem Integrations, tools, library vendors NuGet GitHub +
  2. Catalog API Ordering API PostgreSQL Order Service Order Processor Client

    Apps Event Bus OpenAI Cloud Services Payment Service Payment Processor PostgreSQL Identity Service Identity API PostgreSQL Catalog Service Redis Basket Service Basket API PostgreSQL Webhooks Service Webhooks API Webhook Client Admin Services Observability Mobile API Web App Blazor App Mobile App Browser Mobile BFF Ordering API
  3. Smart Defaults Developer Dashboard Orchestration Service Discovery A cloud ready

    stack for building observable, production ready, distributed applications Deployment Integrations
  4. Smart Defaults A cloud ready stack for building observable, production

    ready, distributed applications Developer Dashboard Orchestration Service Discovery Integrations Deployment
  5. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  6. Integrating the Developer Dashboard Standalone docker run --rm -it -p

    18888:18888 -p 4317:18889 -d --name aspire-dashboard mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0 docker run --rm -it ` -p 18888:18888 ` -p 4317:18889 -d ` --name aspire-dashboard ` mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0 .NET Aspire App Host
  7. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  8. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  9. Service Discovery var builder = DistributedApplication.CreateBuilder(args); var apiService = builder.AddProject<Projects.ApiService>("apiservice");

    builder.AddProject<Projects.Web>("webfrontend") .WithReference(apiService); builder.Build().Run(); builder.Services.AddHttpClient<WeatherApiClient>(client => { client.BaseAddress = new("https+http://apiservice"); });
  10. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  11. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  12. A cloud ready stack for building observable, production ready, distributed

    applications Smart Defaults Developer Dashboard Orchestration Service Discovery Integrations Deployment
  13. Highlights 1. A full migration of all components at once

    wasn’t necessary. 2. We opted not to use of ServiceDefaults. 3. To minimize changes, we used a technique I call the 'hosting integration adapter method’. 4. We were able to implement complex migration scenarios that weren't feasible before.
  14. Solution Before After We created a separate solution for Aspire

    AppHost and its dependencies .NET Aspire 9 RC1 makes it simpler You no longer need a .NET workload. Instead, add the Aspire.AppHost.Sdk
  15. Solution Before After I have created a NuGet package Nall.Aspire.Hosting.DependsOn

    to address this issue .NET Aspire 9 RC1 You can now specify that a resource should wait for another resource before starting
  16. Solution Before After We implemented a mechanism to run infrastructure

    and services separately .NET Aspire 9 RC1 The app host now supports persistent containers . This is useful when you want to keep the container running even after the app host has stopped. .NET Aspire 9 RC1 adds a Resource Commands including the “restart” action. If the debugger is attached, it's reattached on restart.
  17. Solution Before After We implemented a mechanism to write environment

    variables provided by Aspire to a .env file
  18. Examples • eShopSupport - A reference .NET application using AI

    for a customer support ticketing system • eShop - A reference .NET application implementing an eCommerce site • eShopOnAzure - A variant of eShop that uses Azure services • cecilphillip/shadowShop - A modified version of the Aspire Shop sample application that adds integration with Stripe for payment processing, temporal for durable workflows, other customer Aspire Integrations • thangchung/practical-dotnet-aspire - The practical .NET Aspire builds on the coffeeshop app business domain