Exemplo n.º 1
0
        public Behaviour ConvertBehaviourChainsToBehaviours(BehaviourChain chain)
        {
            var top = (Behaviour)IoC.Container.GetInstance(chain.Top.Type);

            BuildBehaviours(chain, top);

            return top;
        }
Exemplo n.º 2
0
        public Behaviour ConvertBehaviourChainToBehaviours(BehaviourChain chain)
        {
            var top = (Behaviour)Activator.CreateInstance(chain.Top.Type);

            PopulateBehaviours(chain, top);

            return top;
        }
Exemplo n.º 3
0
        public void BehaviourChains_101()
        {
            var chain = new BehaviourChain();
            chain.Append(new BehaviourNode(typeof(Nick)));
            chain.Append(new BehaviourNode(typeof(Emily)));
            chain.Prepend(new BehaviourNode(typeof(Paul))); // wraps it
            chain.Prepend(new BehaviourNode(typeof(Gregzilla))); // wraps it

            var converter = new Converter();
            var behaviours = converter.ConvertBehaviourChainToBehaviours(chain);
            behaviours.Invoke();
        }
Exemplo n.º 4
0
 private static void BuildBehaviours(BehaviourChain chain, Behaviour top)
 {
     var next = top;
     foreach (var node in chain)
     {
         if (node != chain.Top)
         {
             var inner = (Behaviour) IoC.Container.GetInstance(node.Type);
             next.Inner = inner;
             next = inner;
         }
     }
 }
Exemplo n.º 5
0
 private static void PopulateBehaviours(BehaviourChain chain, Behaviour top)
 {
     var next = top;
     foreach (var node in chain)
     {
         if (node != chain.Top)
         {
             var inner = (Behaviour) Activator.CreateInstance(node.Type);
             next.Inner = inner;
             next = inner;
         }
     }
 }
Exemplo n.º 6
0
        public void IoC_With_Context()
        {
            IoC.Container = new Container();
            IoC.Container.Configure(x =>
                                        {
                                            x.For<IRepository>().Use<BlahRepository>();
                                            x.For<ILogger>().Use<BlahLogger>();
                                            x.For<IRequest>().Use(new SillyRequest()); // equivalent to Http scoped
                                        });

            var chain = new BehaviourChain();
            chain.Append(new BehaviourNode(typeof(RequestParser)));
            chain.Append(new BehaviourNode(typeof(RequiresARepository)));
            chain.Append(new BehaviourNode(typeof(RequiresALogger)));
            chain.Append(new BehaviourNode(typeof(OutputRenderer)));

            var runner = new IoCRunner();
            var behaviours = runner.ConvertBehaviourChainsToBehaviours(chain);
            behaviours.Invoke();
        }