Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var thunkMiddleware     = StandardMiddleware.CreateThunkMiddleware();
            var loggerMiddleware    = StandardMiddleware.CreateStdoutLoggerMiddleware();
            var thunkFirstEnhancer  = Ops.ApplyMiddleware(thunkMiddleware, loggerMiddleware);
            var loggerFirstEnhancer = Ops.ApplyMiddleware(loggerMiddleware, thunkMiddleware);

            CreateTestWithEnhancer("Thunk first", thunkFirstEnhancer);
            CreateTestWithEnhancer("Logger first", loggerFirstEnhancer);

            // You will notice that when thunk middleware is the first parameter of ApplyMiddleware,
            // the messages inside `incrementIfOdd` prints int between the messages in the logger.
            // In other words, logger middleware calls thunk middleware. This happens because the
            // middleware is composed right to left, so the last middleware in the list gets called
            // first, and it in turn calls the other middleware.
        }