Skip to content

Commit

Permalink
Add convenience workflow construction methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Aug 25, 2022
1 parent 8ad878d commit 66b1785
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/modules/Elsa.Workflows.Core/Models/Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ public Workflow(
Root = root;
}

public static Workflow FromActivity(IActivity root) => new(
WorkflowIdentity.VersionOne,
WorkflowPublication.LatestDraft,
new WorkflowMetadata(),
root,
new List<Variable>(),
new Dictionary<string, object>(),
new Dictionary<string, object>());
public Workflow(IActivity root)
{
Root = root;
}

public Workflow()
{
}

public static Workflow FromActivity(IActivity root) => new(root);

/// <summary>
/// Creates a new memory register initialized with this workflow's variables.
Expand All @@ -43,10 +45,10 @@ public MemoryRegister CreateRegister()
return register;
}

public WorkflowIdentity Identity { get; set; }
public WorkflowPublication Publication { get; set; }
public WorkflowMetadata WorkflowMetadata { get; set; }
public ICollection<Variable> Variables { get; init; }
public WorkflowIdentity Identity { get; set; } = WorkflowIdentity.VersionOne;
public WorkflowPublication Publication { get; set; } = WorkflowPublication.LatestAndPublished;
public WorkflowMetadata WorkflowMetadata { get; set; } = new();
public ICollection<Variable> Variables { get; init; } = new List<Variable>();
public Workflow Clone() => (Workflow)((ICloneable)this).Clone();
object ICloneable.Clone() => MemberwiseClone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface IWorkflowBuilder
{
string? DefinitionId { get; }
int Version { get; }
IActivity? Root { get; }
IActivity? Root { get; set; }
ICollection<Variable> Variables { get; set; }
IDictionary<string, object> ApplicationProperties { get; }
IWorkflowBuilder WithDefinitionId(string definitionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public WorkflowRuntimeFeature(IModule module) : base(module)
/// A factory that instantiates a concrete <see cref="IWorkflowDispatcher"/>.
/// </summary>
public Func<IServiceProvider, IWorkflowDispatcher> WorkflowDispatcherFactory { get; set; } = sp => ActivatorUtilities.CreateInstance<TaskBasedWorkflowDispatcher>(sp);

public WorkflowRuntimeFeature AddWorkflow<T>() where T : IWorkflow
{
Workflows.Add<T>();
return this;
}

public override void ConfigureHostedServices() =>
Module
Expand Down

0 comments on commit 66b1785

Please sign in to comment.