Skip to content

Instantly share code, notes, and snippets.

@sfmskywalker
Last active August 1, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfmskywalker/5fd7aeb74c439cd92ef225aaafd75e06 to your computer and use it in GitHub Desktop.
Save sfmskywalker/5fd7aeb74c439cd92ef225aaafd75e06 to your computer and use it in GitHub Desktop.
Building Workflow Driven .NET Applications With Elsa 2 - Part 3
{
"$id": "1",
"definitionId": "21c8e4c36dee486d8fca566881ea79b4",
"versionId": "05f9f30ee43147b5b2edbb5f723f94d2",
"name": "HelloWorld",
"displayName": "Hello World",
"version": 1,
"variables": {
"$id": "2",
"data": {}
},
"customAttributes": {
"$id": "3",
"data": {}
},
"isSingleton": false,
"persistenceBehavior": "WorkflowBurst",
"deleteCompletedInstances": false,
"isPublished": true,
"isLatest": true,
"activities": [
{
"$id": "4",
"activityId": "06b927c7-be55-4958-97b5-ab84393eebc6",
"type": "HttpEndpoint",
"displayName": "HTTP Endpoint",
"persistWorkflow": false,
"loadWorkflowContext": false,
"saveWorkflowContext": false,
"properties": [
{
"$id": "5",
"name": "Path",
"expressions": {
"$id": "6",
"Literal": "/hello-world"
}
},
{
"$id": "7",
"name": "Methods",
"expressions": {
"$id": "8",
"Json": "[\"GET\"]"
}
},
{
"$id": "9",
"name": "ReadContent",
"expressions": {
"$id": "10"
}
},
{
"$id": "11",
"name": "TargetType",
"expressions": {
"$id": "12"
}
}
],
"propertyStorageProviders": {}
},
{
"$id": "13",
"activityId": "bbca4608-e55f-4d81-a87d-f2c10b336f58",
"type": "WriteHttpResponse",
"displayName": "HTTP Response",
"persistWorkflow": false,
"loadWorkflowContext": false,
"saveWorkflowContext": false,
"properties": [
{
"$id": "14",
"name": "Content",
"expressions": {
"$id": "15",
"Literal": "Hello World"
}
},
{
"$id": "16",
"name": "ContentType",
"expressions": {
"$id": "17"
}
},
{
"$id": "18",
"name": "StatusCode",
"expressions": {
"$id": "19"
}
},
{
"$id": "20",
"name": "CharSet",
"expressions": {
"$id": "21"
}
},
{
"$id": "22",
"name": "ResponseHeaders",
"expressions": {
"$id": "23"
}
}
],
"propertyStorageProviders": {}
}
],
"connections": [
{
"$id": "24",
"sourceActivityId": "06b927c7-be55-4958-97b5-ab84393eebc6",
"targetActivityId": "bbca4608-e55f-4d81-a87d-f2c10b336f58",
"outcome": "Done"
}
],
"id": "05f9f30ee43147b5b2edbb5f723f94d2"
}
using System;
using System.IO;
using Elsa.Persistence.EntityFramework.Core.Extensions;
using Elsa.Providers.Workflows;
using Elsa.Server.Hangfire.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Storage.Net;
namespace DocumentManagement.Workflows.Extensions
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddWorkflowServices(this IServiceCollection services, Action<DbContextOptionsBuilder> configureDb)
{
return services.AddElsa(configureDb);
}
private static IServiceCollection AddElsa(this IServiceCollection services, Action<DbContextOptionsBuilder> configureDb)
{
services
.AddElsa(elsa => elsa
// Use EF Core's SQLite provider to store workflow instances and bookmarks.
.UseEntityFrameworkPersistence(configureDb)
// Use Console activities for testing & demo purposes.
.AddConsoleActivities()
// Use Hangfire to dispatch workflows from.
.UseHangfireDispatchers()
// Configure Email activities.
.AddEmailActivities()
// Configure HTTP activities.
.AddHttpActivities()
);
// Get directory path to current assembly.
var currentAssemblyPath = Path.GetDirectoryName(typeof(ServiceCollectionExtensions).Assembly.Location);
// Configure Storage for BlobStorageWorkflowProvider with a directory on disk from where to load workflow definition JSON files from the local "Workflows" folder.
services.Configure<BlobStorageWorkflowProviderOptions>(options => options.BlobStorageFactory = () => StorageFactory.Blobs.DirectoryFiles(Path.Combine(currentAssemblyPath, "Workflows")));
return services;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment