[17.0] Document breaking change: Azure Cosmos DB `configureClientOptions` callback now receives `IServiceProvider`

Aperta Adatta ai principianti
#2,130 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, markdown
Ambito
documentation

Direzione di ricerca

Leggi la tabella delle modifiche incompatibili in src/frontend/src/content/docs/whats-new/aspire-13-3.mdx e la sezione configureClientOptions di src/frontend/src/content/docs/integrations/cloud/azure/azure-cosmos-db/azure-cosmos-db-connect.mdx. Aggiungi la modifica incompatibile di Aspire 17.0 alla pagina What's new della versione 17.0 quando sarà disponibile e valuta l’aggiunta di un esempio aggiornato di callback alla pagina dell’integrazione. Il lavoro è completato quando la modifica, il suo impatto sulla compatibilità e la migrazione sono documentati con precisione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In Aspire 17.0, the configureClientOptions parameter in the stable Aspire.Microsoft.Azure.Cosmos client integration changed from Action<CosmosClientOptions>? to Action<IServiceProvider, CosmosClientOptions>?. The old signatures were removed rather than kept as overloads. This breaks both source and binary compatibility, so it should be listed in the 17.0 breaking changes.

The change applies to all six methods on Microsoft.Extensions.Hosting.AspireMicrosoftAzureCosmosExtensions:

  • AddAzureCosmosClient and AddKeyedAzureCosmosClient
  • AddAzureCosmosContainer and AddKeyedAzureCosmosContainer
  • AddAzureCosmosDatabase and AddKeyedAzureCosmosDatabase
- Action<CosmosClientOptions>? configureClientOptions = null
+ Action<IServiceProvider, CosmosClientOptions>? configureClientOptions = null

Why it changed

The callback can now resolve services from DI while it configures the client. For example, it can add RequestHandler instances that have their own dependencies to CosmosClientOptions.CustomHandlers.

Impact

  • Source: passing a single-parameter lambda, a method group, or an Action<CosmosClientOptions> variable as configureClientOptions no longer compiles. Calls that don't pass configureClientOptions still compile.
  • Binary: assemblies compiled against 13.x that call any of these methods throw MissingMethodException at run time, even if they don't pass configureClientOptions.
  • Behavior: configureClientOptions now runs when the CosmosClient is first resolved from DI, not during registration, so an exception thrown by the callback surfaces at that point. Likewise, CosmosDatabaseBuilder.AddKeyedContainer no longer creates the CosmosClient during registration, so missing connection information is reported when the container is first resolved.

Migration

Add an IServiceProvider parameter to the callback:

// Aspire 13.x
builder.AddAzureCosmosClient("cosmos", configureClientOptions: options =>
{
    options.ApplicationName = "myapp";
});

// Aspire 17.0
builder.AddAzureCosmosClient("cosmos", configureClientOptions: (services, options) =>
{
    options.ApplicationName = "myapp";
});

The new parameter can resolve services that the options need:

builder.Services.AddSingleton<MyRequestHandler>(); // MyRequestHandler derives from RequestHandler

builder.AddAzureCosmosClient("cosmos", configureClientOptions: (services, options) =>
{
    options.CustomHandlers.Add(services.GetRequiredService<MyRequestHandler>());
});

Where to document

  • Add a row to the ⚠️ Breaking changes table on the 17.0 What's new page. There's no whats-new/aspire-17*.mdx on main yet; follow the table in aspire-13-3.mdx.
  • Consider adding a configureClientOptions example next to the inline delegates example in azure-cosmos-db-connect.mdx, which only shows configureSettings today. The package README has an updated example.
Lingua principale
MDX
Stelle
202
Fork
99
Merge medio
2g 10h
PR unite (30g)
97

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/aspire.dev

Tutte le issue di microsoft/aspire.dev

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.