Skip to content

Add a guard behavior for validation and authorization #268

Description

@kzu

Summary

Ship a guard behavior: a predicate over the invocation that either returns an exception or calls next. Use it for validation, null checks, and authorization, without DataAnnotations and without an expression language.

API

Construct the behavior with Func<IMethodInvocation, Exception?>. A null result calls next. A non-null exception fails the invocation, and next is not called.

Behavior

  • The predicate does not call next.
  • For a synchronous member, the exception is returned through CreateExceptionReturn, so the stunt throws it on the caller thread.
  • For a Task or ValueTask member, fail before producing the target's awaitable: the returned awaitable is faulted with the predicate's exception.

Acceptance

  • A predicate that returns ArgumentNullException runs the target zero times, and the caller observes that exception.
  • A predicate that returns null runs the target once.

Back this issue
Back this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions