diff --git a/aspnetcore/fundamentals/openapi/using-openapi-documents.md b/aspnetcore/fundamentals/openapi/using-openapi-documents.md index b07ab2643cba..9a497eec58fb 100644 --- a/aspnetcore/fundamentals/openapi/using-openapi-documents.md +++ b/aspnetcore/fundamentals/openapi/using-openapi-documents.md @@ -109,21 +109,22 @@ public class DocumentService { private readonly IOpenApiDocumentProvider _documentProvider; - public DocumentService(IOpenApiDocumentProvider documentProvider) + public DocumentService([FromKeyedServices("v1")] IOpenApiDocumentProvider documentProvider) { _documentProvider = documentProvider; } - public async Task GetApiDocumentAsync() + public Task GetApiDocumentAsync(CancellationToken cancellationToken = default) { - return await _documentProvider.GetOpenApiDocumentAsync("v1"); + return _documentProvider.GetOpenApiDocumentAsync(cancellationToken); } } ``` -Register the service in your DI container: +Register the service in your DI container. Note that service key "v1" should match the document name passed to `AddOpenApi`: ```csharp +builder.Services.AddOpenApi("v1"); builder.Services.AddScoped(); ```