Skip to content

Commit 51033a9

Browse files
Add parameterless extension method for creating IApiVersionDescriptionProvider
1 parent cff65fc commit 51033a9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning.ApiExplorer;
4+
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Routing;
7+
using Microsoft.Extensions.Primitives;
8+
9+
/// <summary>
10+
/// Provides extension methods for <see cref="IApiVersionDescriptionProviderFactory"/>.
11+
/// </summary>
12+
[CLSCompliant( false )]
13+
public static class IApiVersionDescriptionProviderFactoryExtensions
14+
{
15+
/// <summary>
16+
/// Creates and returns an API version description provider.
17+
/// </summary>
18+
/// <param name="factory">The extended <see cref="IApiVersionDescriptionProviderFactory"/>.</param>
19+
/// <returns>A new <see cref="IApiVersionDescriptionProvider">API version description provider</see>.</returns>
20+
public static IApiVersionDescriptionProvider Create( this IApiVersionDescriptionProviderFactory factory )
21+
{
22+
ArgumentNullException.ThrowIfNull( factory );
23+
return factory.Create( new EmptyEndpointDataSource() );
24+
}
25+
26+
private sealed class EmptyEndpointDataSource : EndpointDataSource
27+
{
28+
public override IReadOnlyList<Endpoint> Endpoints { get; } = [];
29+
30+
public override IChangeToken GetChangeToken() => new CancellationChangeToken( CancellationToken.None );
31+
32+
public override IReadOnlyList<Endpoint> GetGroupedEndpoints( RouteGroupContext context ) => Endpoints;
33+
}
34+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy