Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Flow Usage Question #3

Open
pirvudoru opened this issue Mar 1, 2016 · 1 comment
Open

Flow Usage Question #3

pirvudoru opened this issue Mar 1, 2016 · 1 comment

Comments

@pirvudoru
Copy link

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());
@akarpov89
Copy link
Owner

Hi Doru!
Thanks for your feedback.

Yes, you correctly understood how to set input and output.
I'll work on supporing generic flows, using an existing DI container and other topics you mentioned.
Some of these features will be available soon, some a little bit later.
Stay tuned!

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants