Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aspnetcore/fundamentals/openapi/using-openapi-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenApiDocument> GetApiDocumentAsync()
public Task<OpenApiDocument> 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<DocumentService>();
```

Expand Down