Open brunoborges opened 5 years ago
cc: @paulbatum
My initial reaction to this proposal is:
@paulbatum: few comments.
I worry more about handling annotations differently in Java purely for readability. I wonder if a potential feature request and pattern we could think about for multiple languages would be allowing you to pass in an options
object instead of having to define parameters inline. So could keep consistency and existing patterns but sometime post-GA enabling something like:
public CosmosDbTriggerOptions cosmosDbOptions = ...
@FunctionName("cosmosDBMonitor")
public void cosmosDbProcessor(@CosmosDBTrigger(cosmosDbOptions) String[] items, final ExecutionContext context )
{
context.getLogger().info(items.length + "item(s) is/are changed.");
}
Something like above may have added benefits of making it really easy to share config between multiple output bindings to the same source.
Regardless though I think may be better ways to solve readability than making attributes method level
@jeffhollan understand your concern, although what you provide as example does not work in Java and unlikely to every be implemented in the language in the future due to how annotations work
@brunoborges I might be missing something, but isnt it quite fragile to have method level attributes that are then mapped to parameters by name? As far as I can tell, if you rename the parameter the attributes would break.
Currently, triggers and bindings are defined at the parameter-level. Given the amount of config parameters that the annotations may require, or that the user may want to set, this approach often makes the code extremely hard to read.
Only one trigger is allowed on a (Java method) function, making Trigger a definitive candidate to be a Method annotation, instead of a method-parameter annotation.
Example of Cosmos DB trigger:
In the example above, it is hard to quickly find where the actual method body starts.
A better approach would be to move the annotation to the method-level:
Moving the annotation to the method level, requires a new way to bind the trigger and the input object. This can be done in two ways:
parameter
where the user defines the name of the method parameter that will take the inputThe code snippet above covers option 1.
For option 2, an example would be:
In the above example for option 2, a new annotation called
@TriggerObject
is defined to bind the trigger with the method-parameter.This structure provides two benefits:
The same approach should be considered for other types: Bindings, and Outputs.
Request for feedback: @JonathanGiles, @pragnagopa, @asavaritayal, @eduardolaureano, @jeffhollan