https://github.com/stuartleeks/durablefunctionstypedsafeactivities
POC of an idea to generate extension methods for Azure Durable Functions to give type-safe, friendly methods to invoke activity functions from the orchestrator
https://github.com/stuartleeks/durablefunctionstypedsafeactivities
Last synced: about 1 year ago
JSON representation
POC of an idea to generate extension methods for Azure Durable Functions to give type-safe, friendly methods to invoke activity functions from the orchestrator
- Host: GitHub
- URL: https://github.com/stuartleeks/durablefunctionstypedsafeactivities
- Owner: stuartleeks
- Created: 2018-02-05T15:09:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-24T11:55:30.000Z (over 7 years ago)
- Last Synced: 2025-02-17T10:49:09.366Z (over 1 year ago)
- Language: C#
- Size: 9.77 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DurableFunctionsTypedSafeActivities
This is a project to test out an idea for creating extension methods to make the syntax for calling
By default, the way to invoke activities is by specifying the function name as a string
```csharp
// Standard way to invoke
outputs.Add(await context.CallActivityAsync("Function1_Hello", "Tokyo"));
outputs.Add(await context.CallActivityAsync("Function1_Hello", "Seattle"));
outputs.Add(await context.CallActivityAsync("Function1_Hello", "London"));
```
There is a T4 template (heavily based on [T4MVC](https://github.com/T4MVC/T4MVC)) that inspects the current project open in Visual Studio and generates a set of extension methods to make the syntax for calling friendlier (and type-safe so that you get compiler errors)
```csharp
// Invoke using extension method helper
outputs.Add(await context.SayHello("Tokyo"));
outputs.Add(await context.SayHello("Seattle"));
outputs.Add(await context.SayHello("London"));
```
## Thoughts
* still needs work, e.g. generating the right namespace
* needs more thought around which parameters to include. Currently just hard-coded to ignore `TextWriter`
* only works in Visual Studio - is there an alternative to T4 Templates that works outside of VS and xplat?
Also considering moving the methods to a helper to avoid name clashes and make it easier to navigate activity methods as below. This does make the syntasx a bit more verbose, but it is still shorter than the original and has the benefits of code completion and compiler checking.
```csharp
// Invoke using extension method helper
outputs.Add(await context.Activities().SayHelloAsync("Tokyo"));
outputs.Add(await context.Activities().SayHelloAsync("Seattle"));
outputs.Add(await context.Activities().SayHelloAsync("London"));
```