question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invocation Filters

See original GitHub issue

We should consider adding an Invoke Filter concept. This is very similar to WebAPI ActionFilters (the problem domain is basically the same). We’ve already had some related asks (see #734, #895). The idea is to provide a declarative programming model that allows people to attach filters to their job methods, classes, etc. similar to the way filters are specified in WebAPI. The invoke filter will receive a context object that contains everything needed to perform validations, do logging, etc. before any input/output bindings occur and before the function executes. In addition to invocation filters, we’ll also enable different filter types mapping to different stages in the execution pipeline (e.g. exception/error filters). Here’s an sketch:

[ErrorHandler]
public static class Functions
{
    [ValidateOrder]
    public static void ProcessOrder([QueueTrigger(“orders”)] Order order) { … }
}

public class ValidateOrdeAttribute : InvokeFilterAttribute
{
    public override void OnExecuting(FunctionExecutingContext context) 
    {
        // perform validations, etc.
    }

    public override void OnExecuted(FunctionExecutedContext context) 
    {
        // perform validations, etc.
    }
}

This attribute could be applied at the function or class level. We could also support host level as well (e.g. add to JobHostConfiguration service collection). Just like WebAPI ActionFilters, where they can be specified declaratively, as well as at the service config level.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mathewccommented, Jan 20, 2017

@jamesbascle Of course we’d support async filters. Basically we’ll be doing something like WebAPI ActionFilters. As you can see, that model supports sync/async. If you’re asking for something more, please share details.

I realize my sketch code above didn’t make that clear 😃

1reaction
jamesbasclecommented, Mar 23, 2017

It definitely makes sense, but it should be optional. They should be configurable via attributes on a per job function, per job class, and global basis.

On Mar 22, 2017 10:34 PM, “VenkateshSrini” notifications@github.com wrote:

Applying only in function level right? Because each job in an isolated entity. Multiple jobs (dissimilar) could be packaged at runtime in a job host. So I think applying filter globally will not make that much sense

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-webjobs-sdk/issues/980#issuecomment-288599850, or mute the thread https://github.com/notifications/unsubscribe-auth/AD_ohWqZ1gNwaDTFIXkRTXCmyI5tBTQyks5rodpQgaJpZM4Lo0bI .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function Filters · Azure/azure-webjobs-sdk Wiki
Invocation Filters - have both Executing/Executed methods that are called immediately before and immediately after the target job function is ...
Read more >
Do You Know Azure Functions Have Function Filters?
Filter falls under the category of invocation function filter which will get executed whenever an exception occurs in our function.
Read more >
Filters in ASP.NET Core
Learn how filters work and how to use them in ASP.NET Core. ... How filters work; Implementation; Filter scopes and order of execution ......
Read more >
c# - How to use Azure Function filtering with ...
How to use Azure Function filtering with FunctionInvocationFilterAttribute in .Net 5 ... According to this article, Azure Functions can have an ...
Read more >
Do you know Azure Function have Function-Filters?
FunctionInvocationFilterAttribute: Filter used to execute PRE and POST processing logic when target job function is invoked.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found