@@ -29,7 +29,11 @@ namespace AzureFunctionsApp.Entities;
2929/// Example on how to dispatch to an entity which directly implements TaskEntity<TState>. Using TaskEntity<TState> gives
3030/// the added benefit of being able to use DI. When using TaskEntity<TState>, state is deserialized to the "State"
3131/// property. No other properties on this type will be serialized/deserialized.
32+ ///
33+ /// Source generators are used to generate the [Function] method with [EntityTrigger] binding automatically.
34+ /// The generated function will be named "Counter" (based on the class name or the DurableTask attribute value).
3235/// </summary>
36+ [ DurableTask ( nameof ( Counter ) ) ]
3337public class Counter : TaskEntity < int >
3438{
3539 readonly ILogger logger ;
@@ -49,19 +53,21 @@ public int Add(int input)
4953
5054 public void Reset ( ) => this . State = 0 ;
5155
52- [ Function ( "Counter" ) ]
53- public Task DispatchAsync ( [ EntityTrigger ] TaskEntityDispatcher dispatcher )
54- {
55- // Can dispatch to a TaskEntity<TState> by passing a instance.
56- return dispatcher . DispatchAsync ( this ) ;
57- }
56+ // Note: The [Function("Counter")] method is now auto-generated by the source generator.
57+ // The generated code will look like:
58+ // [Function(nameof(Counter))]
59+ // public static Task Counter([EntityTrigger] TaskEntityDispatcher dispatcher)
60+ // {
61+ // return dispatcher.DispatchAsync<Counter>();
62+ // }
5863
5964 [ Function ( "Counter_Alt" ) ]
6065 public static Task DispatchStaticAsync ( [ EntityTrigger ] TaskEntityDispatcher dispatcher )
6166 {
62- // Can also dispatch to a TaskEntity<TState> by using a static method.
63- // However, this is a different entity ID - "counter_alt" and not "counter". Even though it uses the same
64- // entity implementation, the function attribute has a different name, which determines the entity ID.
67+ // This is kept as a manual example showing how to create an alternative entity function
68+ // with a different name. This creates a separate entity ID "counter_alt" vs "counter".
69+ // Even though it uses the same entity implementation, the function attribute has a different name,
70+ // which determines the entity ID.
6571 return dispatcher . DispatchAsync < Counter > ( ) ;
6672 }
6773}
0 commit comments