Skip to content

Instantly share code, notes, and snippets.

@laur3d
laur3d / DynamicOrchestratorTrigger.cs
Created September 11, 2020 06:58
DynamicOrchestrators
public static class DynamicOrchestratorTrigger
{
[FunctionName("DynamicOrchestratorTrigger")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
HttpRequest req, ILogger log,
ExecutionContext executionContext,
[DurableClient] IDurableOrchestrationClient starter)
{
log.LogInformation("C# HTTP trigger function processed a request.");
public class DynamicOrchestrator
{
[FunctionName(nameof(DynamicOrchestrator))]
public async Task<string> Run([OrchestrationTrigger] IDurableOrchestrationContext context,
ExecutionContext executionContext)
{
var input = context.GetInput<OrchestratorInput>();
string greeting = "";
public class DynamicOrchestrator
{
[FunctionName(nameof(DynamicOrchestrator))]
public async Task<string> Run([OrchestrationTrigger] IDurableOrchestrationContext context,
ExecutionContext executionContext)
{
var input = context.GetInput<OrchestratorInput>();
return await context.CallSubOrchestratorAsync<string>(
await context.CallActivityAsync<string>(
public class DetermineOrchestratorToRunActivity
{
[FunctionName(nameof(DetermineOrchestratorToRunActivity))]
public async Task<string> Run([ActivityTrigger] IDurableActivityContext context)
{
var input= context.GetInput<string>();
string nameOfOrchestrator;
switch (input.Length)
[JsonObject(MemberSerialization.OptIn)]
public class ShoppingCartEntity : IShoppingCart
{
[JsonProperty("list")]
private List<CartItem> list { get; set; } = new List<CartItem>();
public void Add(CartItem item)
{
// Get existing
AddItemToCart: [POST] http://localhost:7071/api/cart/{id}/add
GetCartForSession: [GET] http://localhost:7071/api/cart/{id}
RemoveItemFromCart: [POST] http://localhost:7071/api/cart/{id}/remove
[FunctionName("AddItemToCart")]
public static async Task<ActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "cart/{id}/add")] HttpRequestMessage req,
Guid id,
[DurableClient] IDurableEntityClient client )
{
if (id == Guid.Empty)
{
return (ActionResult) new BadRequestObjectResult("Id is required");
}
public class CartItem
{
public Guid ProductId { get; set; }
public int Count { get; set; }
}
[FunctionName("RemoveItemFromCart")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "cart/{id}/remove")] HttpRequestMessage req,
Guid id,
[DurableClient] IDurableClient client, ILogger log)
{
if (id == Guid.Empty)
{
return (ActionResult) new BadRequestObjectResult("Id is required");
[FunctionName("GetCartForSession")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "cart/{id}")] HttpRequestMessage req,
Guid id,
[DurableClient] IDurableClient client,
ILogger log)
{
if (id == Guid.Empty)
{
return (ActionResult) new BadRequestObjectResult("The ID is required");