From e114911d77ea31348052b46115c1179afda65f60 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 13 Sep 2017 22:43:55 -0700 Subject: [PATCH] Introduce [ApiController] This puts a de-facto metadata approach in the box to declare unambiguously 'Hey, I am an API!'. I think this is worth us doing at this point because I haven't really seen anyone in the community running with targeting conventions at equivalence classes of controllers. Now that we're putting API-specific, opinionated behaviors in the box, we need to away to make it opt-in and declarative. --- .../ApiControllerAttribute.cs | 18 ++++++++++++++++++ .../Internal/IApiBehaviorMetadata.cs | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/Microsoft.AspNetCore.Mvc.Core/ApiControllerAttribute.cs create mode 100644 src/Microsoft.AspNetCore.Mvc.Core/Internal/IApiBehaviorMetadata.cs diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ApiControllerAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ApiControllerAttribute.cs new file mode 100644 index 0000000000..98b6f5c084 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Core/ApiControllerAttribute.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Mvc.Internal; + +namespace Microsoft.AspNetCore.Mvc +{ + /// + /// Indicates that a type and all derived types are used to serve HTTP API responses. The presense of + /// this attribute can be used to target conventions, filters and other behaviors based on the purpose + /// of the controller. + /// + [AttributeUsage(AttributeTargets.Class)] + public class ApiControllerAttribute : ControllerAttribute , IApiBehaviorMetadata + { + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/IApiBehaviorMetadata.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/IApiBehaviorMetadata.cs new file mode 100644 index 0000000000..b73c1ba56e --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/IApiBehaviorMetadata.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Microsoft.AspNetCore.Mvc.Internal +{ + /// + /// An interface for . See + /// for details. + /// + public interface IApiBehaviorMetadata : IFilterMetadata + { + } +}