- 
                Notifications
    
You must be signed in to change notification settings  - Fork 716
 
Custom Attributes
        Chris Martinez edited this page Jan 8, 2023 
        ·
        1 revision
      
    In addition to the API versioning options, there are few other customization and extension points. Attributes are the primary mechanism used to decorate the API version metadata with a specific controller type, but the attributes used can be any IApiVersionProvider.
public interface IApiVersionProvider
{
    ApiVersionProviderOptions Options { get; }
    IReadOnlyList<ApiVersion> Versions { get; }
}There are several API version provider attributes defined out-of-the-box:
ApiVersionsBaseAttributeApiVersionAttributeMapToApiVersionAttributeAdvertiseApiVersionsAttribute
These attributes are themselves extensible. For example, you might choose to have your own attributes that are unambiguously a specific version:
[AttributeUsage( AttributeUsage.Class, AllowMultiple = true, Inherited = false )]
public sealed class V1Attribute : ApiVersionAttribute
{
    public V1Attribute() : base( new ApiVersion( new( 2016, 7, 1 ) ) ) { }
}
[V1]
[ApiController]
[Route( "api/[controller]" )]
public class HelloWorldController : ControllerBase
{
    [HttpGet]
    public string Get() => "Hello world!";
}This approach can help centralize API version management and avoid developer typographical errors when implementing a set of services that all use the same API version.
- Home
 - Quick Starts
 - Version Format
 - Version Discovery
 - Version Policies
 - How to Version Your Service
 - API Versioning with OData
 - Configuring Your Application
 - Error Responses
 - API Documentation
 - Extensions and Customizations
 - Known Limitations
 - FAQ
 - Examples