Getting started - aceryan-consulting/aceryansoft.codeflow GitHub Wiki

As already explained, CodeFlow should be designed as an ordered collection of loosely-coupled activities small enough to be delivered during few days.

Let's say we are writing our next awesome library, where we use artificial intelligence to predict customer behaviors (loyalty, spending, etc ...).

First we create our context

Our context should be any class extending CodeFlowContext.

public class AiContext : CodeFlowContext
    {
        public List<Customer> Customers { get; set; } = new List<Customer>();
        public List<Order> Orders { get; set; } = new List<Order>();
        public decimal LoyaltyThreshold { get; set; }
        public decimal SpendingThreshold { get; set; }

        public AiContext()
        {
            // *** no more need since version 1.21.4.19
            // ContextProperties["Customers"] = new ContextProperty(() => Customers, (obj) => { Customers = (List<Customer>)obj; }); 
        }        
    }

Keep in mind that the codeflow context is shared between all activities and we only want to use untyped references to interface (ICodeFlowContext) in our activities.

For instance we can use the code bellow to access context properties or collections.

public void Execute(ICodeFlowContext context, params object[] inputs)
        {
            var loyaltyThreshold = context.GetValue<decimal>("LoyaltyThreshold");
            var customers = context.GetCollection<Customer>("Customers");
            // do any stuff ... 
        }

Then we define the basic structure of our codeflow

let's create some simple classe to wrap our codeflow logic.

  public class AiCodeFlowWrapper
    {
        public void Run()
        {
            var aicodeFlow = new CodeFlow();
            aicodeFlow.StartNew(cfg => {
                cfg.WithContext(() =>
                {
                    return new AiContext(); 
                });
            })
            .Call((ctx, inputs) =>
            {
                Console.WriteLine("Hello World");
            })
            .Close();

            aicodeFlow.Execute();
        }
    }

We create a new CodeFlow instance with an AiContext and then we call a simple delegate to print a message after the execute method.

Continue reading: Middlewares

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