Aspire Community Toolkit

repository·main·Indexed 20 days ago

https://github.com/communitytoolkit/aspire

A suite of community-created integrations and extensions for .NET Aspire. It provides hosting integrations for provisioning resources like databases, message brokers, and runtimes in the Aspire AppHost, as well as client integrations for seamless connection and configuration within application code.

Tokens
67.7K
Snippets
272
Records
341
Agent score
67%

What's inside Aspire Community Toolkit

  1. Overview of Aspire Community Toolkit packages

    main

    The Aspire Community Toolkit provides a collection of community-created integrations and extensions for .NET Aspire. These packages are generally categorized into two types:

    1. Hosting Integrations: Used in the Aspire AppHost to provision and run resources like databases, message brokers, or runtimes (e.g., Hosting.Golang, Hosting.PostgreSQL.Extensions, Hosting.Ollama).
    2. Client Integrations: Used in your application code to provide seamless connection and configuration for the hosted resources (e.g., OllamaSharp, Meilisearch, MinIO.Client).

    Some packages provide extensions for existing core Aspire integrations to add specialized functionality (e.g., Hosting.Redis.Extensions, Hosting.MongoDB.Extensions).

  2. Overview of Aspire Community Toolkit

    main
    The Aspire Community Toolkit is a collection of integrations and extensions designed to enhance development with .NET Aspire. It provides additional components and hosting capabilities that extend the core Aspire experience, contributed by the community and maintained by a core team.
  3. Use CommunityToolkit.Aspire.Hosting.Dapr.AzureExtensions for Dapr and Azure integration

    main
    The CommunityToolkit.Aspire.Hosting.Dapr.AzureExtensions library provides the foundational building blocks for integrating Dapr with Azure resources within an Aspire Hosting application. It is primarily designed as a base layer for more specialized packages (like CommunityToolkit.Aspire.Hosting.Redis.Dapr.Azure) to build upon, providing consistent resource identification and infrastructure configuration for Azure-hosted Dapr components.
  4. Available Aspire Community Toolkit Integrations

    main

    The Aspire Community Toolkit provides a wide range of hosting and client integrations for .NET Aspire. These integrations allow you to easily orchestrate and connect to various runtimes, databases, messaging systems, and cloud services within your Aspire application.

    Common categories of integrations include:

    • Runtimes & Languages: Golang, Java, Node.js, Python, Rust, Deno, Bun, Perl.
    • Databases & Storage: SQLite, PostgreSQL, SQL Server, MySQL, MongoDB, Meilisearch, SurrealDB, RavenDB, Minio, KurrentDB, Elasticsearch.
    • Messaging & Streaming: ActiveMQ, LavinMQ, Redis.
    • Cloud & Infrastructure: Azure Extensions, Dapr, K3s, Kind, Bitwarden Secret Manager.
    • Developer Tools: MailPit, k6, Flagd, GoFeatureFlag, SQL Database Projects.
  5. Configure telemetry routing for OpenTelemetry Collector

    main

    There are two ways to route telemetry from your projects to the OpenTelemetry Collector:

    1. Manual Redirection: Use .WithOpenTelemetryCollectorRouting(collector) on specific projects or resources. Only the resources explicitly called will forward their telemetry to the collector.
    2. Automatic Redirection: Call .WithAppForwarding() on the collector instance. This automatically forwards telemetry for all projects and resources that have the OtlpExporterAnnotation applied.
    // Manual approach
    builder.AddProject<Projects.MyApi>("api")
        .WithOpenTelemetryCollectorRouting(collector);
    
    // Automatic approach
    var collector = builder.AddOpenTelemetryCollector("collector")
        .WithConfig("./config.yaml")
        .WithAppForwarding();
    
    builder.AddProject<Projects.MyApi>("api");
  6. How Bitwarden secrets are persisted via IDeploymentStateManager

    main

    The integration uses IDeploymentStateManager to read and write the per-environment deployment state file (located at ~/.aspire/deployments/{sha}/{env}.json). This file allows Aspire to persist parameter values across different aspire deploy runs.

    Workflow:

    1. A pre-sync step performs inline authentication and writes resolved Bitwarden values (and prompted credentials) to the deployment state.
    2. The deployment state file is loaded as a JSON configuration source at AppHost startup using AddJsonFile(..., reloadOnChange: false).
    3. After writing to the state and calling IConfigurationRoot.Reload(), the updated values become visible to ParameterResource._lazyValue when evaluated by ParameterProcessor.InitializeParametersAsync in the process-parameters step.

    Breakage Signal: If the ASPIREPIPELINES002 diagnostic stops compiling, or if the state-file path or JSON structure changes, the value round-trip will break.

  7. Understand Experimental APIs in Aspire Community Toolkit

    main

    Some APIs in the Aspire Community Toolkit are decorated with the [ExperimentalAttribute]. This indicates that the API is not intended for production use and is subject to change or removal without notice.

    There are three primary reasons an API might be marked as experimental:

    1. Intermediary Solutions (CTASPIRE001): The API serves as a workaround or a bridge for a feature that is currently missing or private in .NET Aspire. Once the feature is officially added to Aspire, this toolkit API will be marked as obsolete and eventually removed.
    2. Unstable Implementation (CTASPIRE002): The underlying implementation is unstable, or test coverage is inconsistent. No guarantees are made regarding functionality or stability.
    3. Perl Hosting Integration (CTASPIREPERL001): Specific APIs related to Perl hosting are currently experimental and may change.

    When using these APIs, you may encounter diagnostics that you should only suppress if you intentionally opt into the experimental surface.

  8. Understand BitwardenSecretResource value resolution priority

    main

    When a component requests a secret value via IValueProvider.GetValueAsync, the BitwardenSecretResource follows a specific priority order to ensure the authoritative remote state is used:

    1. Bitwarden resolved-secret cache: This is the highest priority. It is populated during the sync phases (Phase 2/2.5) or during provisioning. It represents the actual state in Bitwarden.
    2. Managed Secrets Fallback: For managed secrets, if the cache is empty, the resource falls back to the ParameterResource mechanism (waiting for values provided via configuration or user input). This serves as the "write path" for new secrets.
    3. Reference-only Fallback: For reference-only secrets, if the Bitwarden cache is empty (which typically only happens before Phase 2.5 completes), it returns null.
  9. Understand [AspireExport] and polyglot apphosts

    main

    The [AspireExport] attribute is used to register types and methods with the Aspire Type System (ATS). This allows them to be called from polyglot apphosts (such as TypeScript or Python) via the JSON-RPC remote host.

    • Resource Types: Carry [AspireExport] to register their type IDs.
    • Extension Methods: Methods like AddBitwardenSecretManager, GetSecret, AddSecret, and WithReference carry [AspireExport] to define the polyglot API surface.
    • Exclusions: C# ergonomics overloads or methods with ATS-incompatible parameters (like EndpointReference or generic callback types) are marked with [AspireExportIgnore] to explicitly prevent them from being exported.

    Breakage Signal: If the ASPIREATS001 diagnostic stops compiling, the export mechanism has changed.

  10. How Bitwarden parameter collection works (Four-phase model)

    main

    The resource uses a four-phase approach to collect parameters, remaining in the Waiting state in the Aspire dashboard until all inputs are ready. This ensures the dashboard's "Parameters need values" banner only disappears once the resource is truly ready to run.

    1. Phase 1 — Authentication: The resource waits for the management access token. It authenticates with Bitwarden immediately. A missing or invalid token causes an immediate Exited state (exit code 1).
    2. Phase 2 — Upstream Managed Secret Sync: After authentication, the resource checks Bitwarden for existing managed secrets. If a secret exists in Bitwarden but is missing locally, the provisioner automatically binds the value to the resource's cache. This automatically clears the "Parameters need values" banner for those secrets.
    3. Phase 2.5 — Upstream Reference Secret Sync: The resource fetches values for reference-only secrets (declared via GetSecret). If a referenced secret does not exist in Bitwarden, the provisioner throws an error immediately rather than prompting the user.
    4. Phase 3 — Remaining Parameters: The resource waits for any remaining project, organization, or managed secret values that were not found upstream. Once all values are gathered, the resource transitions to Running and begins provisioning.
  11. Understand the BitwardenSecretResource lifecycle and states

    main

    During a local run, the BitwardenSecretResource follows a state machine to manage authentication and parameter collection. Understanding these states helps in debugging provisioning delays or failures.

    StateMeaning
    NotStartedResource registered, initialization not yet started
    WaitingWaiting for one or more parameter values (during any of the four collection phases)
    RunningAll values collected; actively provisioning project and secrets
    FinishedProvisioning succeeded; dependent resources may start
    Exited (exit code 1)Authentication or provisioning failed; dependent resources will also error

    Important: To ensure your application starts only after Bitwarden is ready, you must explicitly call .WaitForCompletion(bitwarden) in your AppHost code for any dependent resources.