This repository was archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Flow Usage Question #3
Copy link
Copy link
Open
Description
I am trying to implement BL using Flows. Is there any opinionated way to:
- set input to a Flow
- get output for a Flow
- use an existing Dependency container (Microsoft.Extensions.DependencyInjection)
From what i see from the docs / src a flow does not have an extensibility point to replace the DI container. An option of setting input is to pass it when constructing the flow via TInput Ctor arg / Property and get the output after run from another Property IValue<TOutput> that is updated after the last activity is executed.
A few observations about the design:
- Flows must be transient - downside the FlowDescriptor gets rebuilt at every run, container is reconfigured every time
- No option for composing flows (eg: a Flow to be considered an activity on it's own) - not an issue actually, maybe not actually desired to allow flow composition
Sample for Flow with I/O (most probably not best way to do it):
public abstract class Flow<TInput, TOutput> : Flow
{
public override string Name => GetType().Name;
protected TInput Input { get; set; }
protected Variable<TOutput> Output { get; set; }
// Sync example
public TOutput Run(TInput input)
{
Input = input;
Run().Wait();
return Output.CurrentValue;
}
protected abstract void BuildCore(FlowBuilder builder);
protected override void Build(FlowBuilder builder)
{
Output = builder.Variable<TOutput>();
BuildCore(builder);
builder.WithDefaultCancellationHandler<DefaultCancelationandler>()
.WithDefaultFaultHandler<DefaultFaultHandler>();
}
}
public class XFlow : Flow<XInput, XOutput>
{
protected override void BuildCore(FlowBuilder builder)
{
var activity = builder.Activity<XActivity>();
activity.Bind(a => a.Input).To(Input);
activity.OnCompletionUpdate(Output, activityOutput => new XOutput());
builder.WithInitialNode(activity);
}
}Usage:
XOutput output = new XFlow().Run(new XInput());
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels