Basic Concepts - aceryan-consulting/aceryansoft.codeflow GitHub Wiki

Core Concepts

Activity Is a basic execution step. It can be called as :

  • a delegate returning an IExecutionContext (ActivityDelegate).
  • a delegate returning void (ActivityCallDelegate). In this case the framework assume that it is a succeeded ActivityDelegate.
  • a method invoked in object implementing interface ICodeFlowActivity.

ActivityFlow is a wrapper of an activity that manage his execution logic.

ContainerFlow Is a sub class of ActivityFlow and contains a collection of child ActivityFlow. ContainerFlow ca be divided in 3 categories :

  • SequenceContainerFlow (If,Switch,While) : execute contained activities sequentially.
  • IteratorContainerFlow (Foreach,ParallelForeach) : Iterate through a list and execute contained activities (sequentially/in parallel) for each element in the list.
  • ParallelContainerFlow (Parallel) : execute contained activities in parallel.

ServiceResolver A delegate who help resolve required dependencies. The framework use the definition Func<Type, string, object> to let any caller use his preferred Dependency injection framework (Autofac,Ninject,Unity,etc ...)

CodeFlowContext A shared class implementing ICodeFlowContext and used to get and pass data through each activity during execution.

Middleware Coming from asp.net core concepts with CodeFlowContext instead of HTTP request , it is a component assembled into an application pipeline to handle requests and responses. Each component :

  • Chooses whether to pass the request to the next component in the pipeline.
  • Can perform work before and after the next component in the pipeline. Middleware pipeline start before your execution code .It is for instance useful for global exception handling. For more information please read ASP.NET Core Middleware .

ActivityFilter It is a component assembled into an application pipeline to run code before and after all activities. ActivityFilter pipeline is for instance useful for logging each activity execution details.

CodeFlow
Base class to set up your long running process and use the framework fluent api.

Fluent api

To keep it short and simple, please read bellow the basic structure of the fluent api. The details of each implementations can be found in the source code.

    public interface ICommonFlowApi<T>
    {
        T Do(ActivityDelegate activity);
        T Do(ICodeFlowActivity instance);
        T Do<TInstance>(string instanceName = "") where TInstance : ICodeFlowActivity;

        T Call(ActivityCallDelegate activity);
        T Call(ICodeFlowActivityCall instance);
        T Call<TInstance>(string instanceName = "") where TInstance : ICodeFlowActivityCall;

        IFunctionFlowApi<T> Function(ActivityFunctionDelegate activity, ICodeFlowActivityFunction instance = null);
        IFunctionFlowApi<T> Function(ICodeFlowActivityFunction instance);
        IFunctionFlowApi<T> Function<TInstance>(string instanceName = "") where TInstance : ICodeFlowActivityFunction;
    }

    public interface ILoopFlowApi<T,TRes> : ICommonFlowApi<T>
    {
        TRes If(Func<ICodeFlowContext, object[], bool> condition, Action<FlowContainerConfig> configAction = null);
        TRes While(Func<ICodeFlowContext, object[], bool> condition, Action<FlowContainerConfig> configAction = null);
        ISwitchFlowApi<TRes> Switch(Func<ICodeFlowContext, object[], object> switchExpression);
        IForEachFlowApi<TRes> ForEach(Func<ICodeFlowContext, object[], List<object>> iterator, int packetSize = 0);
    }

    public interface IFlowApi<T> : ILoopFlowApi<T,T>
    {
        T CallCodeFlow(Action<ICallFlowApi> codeFlowBlock);
        T Parallel();
        T Close();
    }

    public interface ICallFlowApi : IFlowApi<ICallFlowApi>
    {

    }

    public interface ICodeFlowApi : IFlowApi<ICodeFlowApi>
    {
        ICodeFlowApi RestorePoint(string restorePointId, Action<string, string, object[], ICodeFlowContext> contextSaver
            , Func<string, string, ICodeFlowContext> contextProvider);
    }

Continue reading: Getting-started

⚠️ **GitHub.com Fallback** ⚠️