Esempio n. 1
0
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder> ().Bind <IInstanceProvider> ().ToValue(injectionBinder);
     injectionBinder.Bind <ISequencer> ().Bind <ICommandBinder>().To <Sequencer> ().ToSingleton();
     sequencer = injectionBinder.GetInstance <ISequencer> () as ISequencer;
 }
Esempio n. 2
0
		public void SetUp()
		{
			injectionBinder = new InjectionBinder();
			injectionBinder.Bind<IInjectionBinder> ().Bind<IInstanceProvider> ().ToValue (injectionBinder);
			injectionBinder.Bind<ICommandBinder> ().To<CommandBinder> ().ToSingleton ();
			commandBinder = injectionBinder.GetInstance<ICommandBinder> ();
		}
Esempio n. 3
0
        private List <Type> InjectSignalParameters(object[] parameters)
        {
            var types         = signal.GetTypes();
            var injectedTypes = new List <Type>();

            foreach (var type in types)
            {
                var isFound = false;
                foreach (var parameter in parameters)
                {
                    if (parameter == null)
                    {
                        throw new InjectionException("Attempt to bind null value into Command: " + currentCommand);
                    }
                    if (type.IsInstanceOfType(parameter))
                    {
                        binder.Bind(type).ToInstance(parameter);
                        injectedTypes.Add(type);
                        isFound = true;
                    }
                }
                if (!isFound)
                {
                    throw new InjectionException("Cannot find value to inject into Command: " + currentCommand + " for type: " + type);
                }
            }
            return(injectedTypes);
        }
Esempio n. 4
0
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind<IInjectionBinder> ().ToValue (injectionBinder);
     injectionBinder.Bind<ISequencer> ().Bind<ICommandBinder>().To<Sequencer> ().ToSingleton ();
     sequencer = injectionBinder.GetInstance<ISequencer> () as ISequencer;
 }
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder> ().ToValue(injectionBinder);
     injectionBinder.Bind <ICommandBinder> ().To <CommandBinder> ().ToSingleton();
     commandBinder = injectionBinder.GetInstance <ICommandBinder> () as ICommandBinder;
 }
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder>().Bind <IInstanceProvider>().ToValue(injectionBinder);
     injectionBinder.Bind <ICommandBinder>().To <SignalCommandBinder>().ToSingleton();
     commandBinder = injectionBinder.GetInstance <ICommandBinder>() as ICommandBinder;
     injectionBinder.Bind <TestModel>().ToSingleton();
 }
        public void SetUp()
        {
            injectionBinder = new InjectionBinder();
            injectionBinder.Bind <IInjectionBinder>().Bind <IInstanceProvider>().ToValue(injectionBinder);
            injectionBinder.Bind <ICommandBinder> ().To <CommandBinder> ().ToSingleton();

            commandBinder = injectionBinder.GetInstance <ICommandBinder> ();
            (commandBinder as IPooledCommandBinder).usePooling = false;
        }
		public void SetUp()
		{
			injectionBinder = new InjectionBinder ();
			injectionBinder.Bind<IInjectionBinder>().Bind<IInstanceProvider>().ToValue(injectionBinder);
			injectionBinder.Bind<ICommandBinder> ().To<CommandBinder> ().ToSingleton();

			commandBinder = injectionBinder.GetInstance<ICommandBinder> ();
			(commandBinder as IPooledCommandBinder).usePooling = false;
		}
        public void SetUp()
        {
            injector = new InjectionBinder();
            injector.Bind <CaptureMove>().To <CaptureMove>();

            piecePlacedSignal = Substitute.For <PiecePlacedSignal>();
            injector.Bind <PiecePlacedSignal>().To(piecePlacedSignal);

            grid = new Grid(NumRows, NumCols);
        }
Esempio n. 10
0
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder>().Bind <IInstanceProvider>().ToValue(injectionBinder);
     injectionBinder.Bind <IEventDispatcher>().To <EventDispatcher>().ToSingleton();
     injectionBinder.Bind <ICommandBinder>().To <EventCommandBinder>().ToSingleton();
     commandBinder   = injectionBinder.GetInstance <ICommandBinder>();
     eventDispatcher = injectionBinder.GetInstance <IEventDispatcher>();
     (eventDispatcher as ITriggerProvider).AddTriggerable(commandBinder as ITriggerable);
     BadCommand.TestValue = 0;
 }
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind<IInjectionBinder>().Bind<IInstanceProvider>().ToValue(injectionBinder);
     injectionBinder.Bind<IEventDispatcher>().To<EventDispatcher>().ToSingleton();
     injectionBinder.Bind<ICommandBinder>().To<EventCommandBinder>().ToSingleton();
     commandBinder = injectionBinder.GetInstance<ICommandBinder>();
     eventDispatcher = injectionBinder.GetInstance<IEventDispatcher>();
     (eventDispatcher as ITriggerProvider).AddTriggerable(commandBinder as ITriggerable);
     BadCommand.TestValue = 0;
 }
		public void SetUp()
		{
			injectionBinder = new InjectionBinder ();
			injectionBinder.Bind<IInjectionBinder>().Bind<IInstanceProvider>().ToValue(injectionBinder);
			injectionBinder.Bind<ICommandBinder> ().To<SignalCommandBinder> ().ToSingleton();

			commandBinder = injectionBinder.GetInstance<ICommandBinder> ();
			pooledCommandBinder = commandBinder as IPooledCommandBinder;
			singleSignal = new Signal<int>();
			doubleSignal = new Signal<int, string>();
			tripleSignal = new Signal<int, string, SimpleInterfaceImplementer>();
		}
Esempio n. 13
0
        private void Awake()
        {
            InjectionBinder = new CrossContextInjectionBinder();
            InjectionBinder.Bind<IInstanceProvider>().Bind<IInjectionBinder>().ToValue(InjectionBinder);
            InjectionBinder.Unbind<ICommandBinder>();
            InjectionBinder.Bind<ICommandBinder>().To<SignalCommandBinder>().ToSingleton();
            commandBinder = InjectionBinder.GetInstance<ICommandBinder>();

            SetupGameBindings();
            SetupMainMenuBindings();
            SetupSinglePlayerBindings();
        }
Esempio n. 14
0
        public void TestCommandIsInjected()
        {
            injectionBinder.Bind <ISimpleInterface> ().To <SimpleInterfaceImplementer> ();
            commandBinder.Bind(singleSignal).To <CommandWithInjectionPlusSignalPayload> ().Pooled();
            TestDelegate testDelegate = delegate
            {
                singleSignal.Dispatch(27);
            };

            //If the injected value were not set, this command would throw a Null Pointer Exception
            Assert.DoesNotThrow(testDelegate);
        }
Esempio n. 15
0
        public void SetUp()
        {
            injectionBinder = new InjectionBinder();
            injectionBinder.Bind <IInjectionBinder>().Bind <IInstanceProvider>().ToValue(injectionBinder);
            injectionBinder.Bind <ICommandBinder> ().To <SignalCommandBinder> ().ToSingleton();

            commandBinder       = injectionBinder.GetInstance <ICommandBinder> ();
            pooledCommandBinder = commandBinder as IPooledCommandBinder;
            singleSignal        = new Signal <int>();
            doubleSignal        = new Signal <int, string>();
            tripleSignal        = new Signal <int, string, SimpleInterfaceImplementer>();
        }
Esempio n. 16
0
        public void TestCommandIsInjected()
        {
            injectionBinder.Bind <ISimpleInterface> ().To <SimpleInterfaceImplementer> ();
            commandBinder.Bind(SomeEnum.ONE).To <CommandWithInjection> ().Pooled();
            TestDelegate testDelegate = delegate
            {
                commandBinder.ReactTo(SomeEnum.ONE);
            };

            //If the injected value were not set, this command would throw a Null Pointer Exception
            Assert.DoesNotThrow(testDelegate);
        }
Esempio n. 17
0
        private void Awake()
        {
            InjectionBinder = new CrossContextInjectionBinder();
            InjectionBinder.Bind <IInstanceProvider>().Bind <IInjectionBinder>().ToValue(InjectionBinder);
            InjectionBinder.Unbind <ICommandBinder>();
            InjectionBinder.Bind <ICommandBinder>().To <SignalCommandBinder>().ToSingleton();
            commandBinder = InjectionBinder.GetInstance <ICommandBinder>();

            SetupGameBindings();
            SetupMainMenuBindings();
            SetupSinglePlayerBindings();
        }
        public void SetUp()
        {
            CommandThrowsErrorIfEventIsNull.result        = 0;
            CommandThrowsErrorIfEventIsNull.timesExecuted = 0;

            injectionBinder = new InjectionBinder();
            injectionBinder.Bind <IInjectionBinder> ().Bind <IInstanceProvider> ().ToValue(injectionBinder);
            injectionBinder.Bind <ICommandBinder> ().To <EventCommandBinder> ().ToSingleton();
            injectionBinder.Bind <IEventDispatcher> ().To <EventDispatcher> ().ToSingleton().ToName(ContextKeys.CONTEXT_DISPATCHER);

            commandBinder = injectionBinder.GetInstance <ICommandBinder> ();
            dispatcher    = injectionBinder.GetInstance <IEventDispatcher> (ContextKeys.CONTEXT_DISPATCHER);
            (dispatcher as ITriggerProvider).AddTriggerable(commandBinder as ITriggerable);
        }
		public void SetUp()
		{
			CommandThrowsErrorIfEventIsNull.result = 0;
			CommandThrowsErrorIfEventIsNull.timesExecuted = 0;

			injectionBinder = new InjectionBinder();
			injectionBinder.Bind<IInjectionBinder> ().Bind<IInstanceProvider> ().ToValue (injectionBinder);
			injectionBinder.Bind<ICommandBinder> ().To<EventCommandBinder> ().ToSingleton ();
			injectionBinder.Bind<IEventDispatcher> ().To<EventDispatcher> ().ToSingleton ().ToName(ContextKeys.CONTEXT_DISPATCHER);

			commandBinder = injectionBinder.GetInstance<ICommandBinder> ();
			dispatcher = injectionBinder.GetInstance<IEventDispatcher> (ContextKeys.CONTEXT_DISPATCHER);
			(dispatcher as ITriggerProvider).AddTriggerable (commandBinder as ITriggerable);
		}
Esempio n. 20
0
        public void SetUp()
        {
            var gridManager = Substitute.For <IGridManager>();
            var grid        = Substitute.For <IGrid>();

            grid.Dimensions.Returns(new Vector2Int(10, 20));
            grid.Interval.Returns(0.05f);
            grid.BlockSize.Returns(2.8f);

            gridManager.Grid.Returns(grid);
            _injectionBinder = new InjectionBinder();
            _injectionBinder.Bind <IGridManager>().ToValue(gridManager);
            _injectionBinder.Bind <IShapeManager>().To <ShapeManager>();
        }
Esempio n. 21
0
        public void TestExecuteWithInjection()
        {
            //SequencerCommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer> ().ToSingleton();

            //Bind the trigger to the command
            sequencer.Bind(SomeEnum.ONE).To <SequenceCommandWithInjection>();
            sequencer.ReactTo(SomeEnum.ONE);

            //The command should set the value to 100
            ISimpleInterface instance = injectionBinder.GetInstance <ISimpleInterface>() as ISimpleInterface;

            Assert.AreEqual(100, instance.intValue);
        }
Esempio n. 22
0
        public void SetUp()
        {
            injector = new InjectionBinder();
            injector.Bind <CaptureMove>().To <CaptureMove>();
            injector.Bind <IInjectionBinder>().ToValue(injector);
            injector.Bind <PiecePlacedSignal>().To <PiecePlacedSignal>();

            MoveRuleFactory ruleFactory = new MoveRuleFactory();

            ruleFactory.InjectionBinder = injector;

            grid      = new Grid(NumRows, NumCols);
            _instance = ruleFactory.BuildDiagonalMoveRule();
        }
Esempio n. 23
0
        public static void Bind(IInjectionBinder injectionBinder)
        {
            injectionBinder.Bind <IWeapon>().To <HockeyStick>().ToName(WeaponId.HockeyStick);
            injectionBinder.Bind <IWeapon>().To <Crowbar>().ToName(WeaponId.Crowbar);
            injectionBinder.Bind <IWeapon>().To <HuntersKnife>().ToName(WeaponId.HuntersKnife);

            /* the smart way with reflection
             * var type = typeof(IWeapon);
             * var weaponTypes = Assembly.GetAssembly(typeof(IWeapon)).GetTypes()
             *  .Where(p => type.IsAssignableFrom(p) && p.BaseType == typeof(Weapon) && !p.IsAbstract);
             *
             * foreach(var t in weaponTypes)
             * {
             *  var id = Enum.Parse(typeof(WeaponId), t.Name);
             *  injectionBinder.Bind<IWeapon>().To(t).ToName(id);
             * }*/
        }
        public void TestNotOnce()
        {
            //CommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer> ().ToSingleton();

            //Bind the trigger to the command
            commandBinder.Bind(SomeEnum.ONE).To <CommandWithInjection>();

            ICommandBinding binding = commandBinder.GetBinding(SomeEnum.ONE) as ICommandBinding;

            Assert.IsNotNull(binding);

            commandBinder.ReactTo(SomeEnum.ONE);

            ICommandBinding binding2 = commandBinder.GetBinding(SomeEnum.ONE) as ICommandBinding;

            Assert.IsNotNull(binding2);
        }
Esempio n. 25
0
        private void InjectViewAndDependencies(IMediationBinding binding, IMediator mediator, IView view, bool triggerPostConstructors)
        {
            var injectionType = binding.ViewInterface != null ? binding.ViewInterface : binding.ViewType;

            if (_bindingsCache.TryGetValue(injectionType, out var injectionBinding))
            {
                injectionBinding.SetValue(view);
                _injectionBinder.Bind(injectionBinding);
                _injectionBinder.Construct(mediator, triggerPostConstructors);
                _injectionBinder.Unbind(injectionBinding);
            }
            else
            {
                injectionBinding = (IInjectionBinding)_injectionBinder.Bind(injectionType).ToValue(view);
                _injectionBinder.Construct(mediator, triggerPostConstructors);
                _injectionBinder.Unbind(injectionType);
                _bindingsCache.Add(injectionType, injectionBinding);
            }
        }
Esempio n. 26
0
    public static void Create(ICommandBinder commandBinder, IInjectionBinder injectionBinder, IMediationBinder mediationBinder)
    {
        //Bind Settings Object
        var settings = Object.FindObjectOfType <UnityNetworkingData>();

        injectionBinder.Bind <UnityNetworkingData>().To(settings).ToSingleton().CrossContext();

        //Bind Mediators to Views
        mediationBinder.Bind <UnityNetworkManagerView>().To <UnityNetworkManagerMediator>();

        //Bind Commands and Signals
        commandBinder.Bind <SetupUnityNetworkingSignal>().To <SetupUnityNetworkingCommand>();
        commandBinder.Bind <SetupUnityNetworkingCompleteSignal>();
    }
Esempio n. 27
0
 protected ICommand getCommand(Type type)
 {
     if (usePooling && pools.ContainsKey(type))
     {
         Pool     pool    = pools [type];
         ICommand command = pool.GetInstance() as ICommand;
         if (command.IsClean)
         {
             injectionBinder.injector.Inject(command);
             command.IsClean = false;
         }
         return(command);
     }
     else
     {
         injectionBinder.Bind <ICommand> ().To(type);
         ICommand command = injectionBinder.GetInstance <ICommand> ();
         injectionBinder.Unbind <ICommand> ();
         return(command);
     }
 }
Esempio n. 28
0
        protected void Awake()
        {
            ContextView contextView = GetComponentInParent <ContextView>();
            IContext    context     = contextView?.context ?? Context.firstContext;

            if (context != null && context is CrossContext)
            {
                injectionBinder = (contextView.context as CrossContext).injectionBinder;
                injectionBinder.Bind <EntityManager>().ToValue(this).ToSingleton().CrossContext();
            }

            ES = GetComponent <EventSource>() ?? FindObjectOfType <EventSource>();
            if (ES == null)
            {
                throw new Exception("Unable to find active EventSource in scene");
            }

            Reset();

            Filters = new List <Action <IModifier, Action <IModifier> > >();
        }
Esempio n. 29
0
 public SingletonBinder(IInjectionBinder binder)
 {
     _binding = binder.Bind <P>();
 }
Esempio n. 30
0
        public void TestGetBindingFlat()
        {
            binder.Bind <InjectableSuperClass> ().To <InjectableSuperClass> ();
            IInjectionBinding binding = binder.GetBinding <InjectableSuperClass> () as IInjectionBinding;

            Assert.IsNotNull(binding);
        }
Esempio n. 31
0
        public void TestTaggedConstructor()
        {
            binder.Bind <ClassWithConstructorParameters> ().To <ClassWithConstructorParameters> ();
            binder.Bind <int> ().ToValue(42);
            binder.Bind <string> ().ToValue("Liberator");
            ClassWithConstructorParameters instance =
                binder.GetInstance <ClassWithConstructorParameters> () as ClassWithConstructorParameters;

            Assert.IsNotNull(instance);
            Assert.AreEqual(42, instance.intValue);
            Assert.AreEqual("Liberator", instance.stringValue);
        }
Esempio n. 32
0
        private void SetupGameBindings()
        {
            InjectionBinder.Bind <GameContext>().ToValue(this);

            commandBinder.Bind <LoadSceneRootCmdSig>().To <LoadSceneRootCmd>();
        }