Skip to content

Commit 1b4b94e

Browse files
committed
Throw exception is [TopicResponseCache] not applied to TopicController
The `[TopicResponseCache]` will only work with the `TopicController`. Initially, this was validated without an exception since it was intended to be registered as a global filter. In the end, however, it made more sense to register it as an attribute filter on the `TopicController` itself, thus automatically registering it with all derived controllers. Given that, it should throw an explicit exception if a developer attempts to add it to any other type of controller. This maintains consistency with the `[ValidateTopic]` attribute, which performs the same validation.
1 parent dd783d6 commit 1b4b94e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

OnTopic.AspNetCore.Mvc/_filters/TopicResponseCacheAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public override void OnActionExecuting(ActionExecutingContext context) {
6565
var controller = context.Controller as TopicController;
6666

6767
if (controller is null) {
68-
return;
68+
throw new InvalidOperationException(
69+
$"The {nameof(TopicResponseCacheAttribute)} can only be applied to a controller deriving from {nameof(TopicController)}."
70+
);
6971
}
7072

7173
/*------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)