예제 #1
0
        void HookupApplicationEvents()
        {
            IInjectionBinder   binder    = ((MainContext)context).injectionBinder;
            IApplicationEvents appEvents = GameApplication.Instance.ApplicationEvents;


            appEvents.Paused      += () => binder.GetInstance <GamePausedSignal>().Dispatch();
            appEvents.Resumed     += t => binder.GetInstance <GameResumedSignal>().Dispatch(t);
            appEvents.LostFocus   += () => binder.GetInstance <FocusLostSignal>().Dispatch();
            appEvents.GainedFocus += () => binder.GetInstance <FocusGainedSignal>().Dispatch();

            ISceneManager sceneManager = _moduleContainer.ServiceResolver.Get <ISceneManager>();

            sceneManager.TransitionOutStarted += s
                                                 => binder.GetInstance <SceneTransitionOutStartedSignal>().Dispatch(s);
            sceneManager.TransitionOutEnded += s =>
                                               binder.GetInstance <SceneTransitionOutEndedSignal>().Dispatch(s);
            sceneManager.TransitionInStarted += s =>
                                                binder.GetInstance <SceneTransitionInStartedSignal>().Dispatch(s);
            sceneManager.TransitionInEnded += s
                                              => binder.GetInstance <SceneTransitionInEndedSignal>().Dispatch(s);
            sceneManager.SceneLoadStarted += s =>
                                             binder.GetInstance <SceneLoadStartedSignal>().Dispatch(s);
            sceneManager.SceneLoaded += s =>
                                        binder.GetInstance <SceneLoadedSignal>().Dispatch(s);
        }
예제 #2
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()
        {
            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 TestExecuteWithInjection()
        {
            //CommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer> ().ToSingleton();

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

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

            Assert.AreEqual(100, instance.intValue);
        }
		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);
		}
예제 #7
0
        public bool CheckSide_Correct(int xCoordinate, int sizeX, int step)
        {
            var gridManagerResolve = _injectionBinder.GetInstance <IGridManager>();

            var result = gridManagerResolve.Grid.CheckSide(xCoordinate, sizeX, step);

            return(result);
        }
예제 #8
0
        public void TestFactoryInjectionGivesUniqueInstances()
        {
            injectionBinder.Bind <ISimpleInterface> ().To <SimpleInterfaceImplementer> ();
            injectionBinder.Bind <Signal <SimpleInterfaceImplementer> > ().To <Signal <SimpleInterfaceImplementer> > ().ToSingleton();
            commandBinder.Bind(SomeEnum.ONE).To <CommandWithInjectionAndSignal> ().Pooled();

            Signal <SimpleInterfaceImplementer> signal = injectionBinder.GetInstance <Signal <SimpleInterfaceImplementer> >();

            signal.AddListener(cb);

            commandBinder.ReactTo(SomeEnum.ONE);
            commandBinder.ReactTo(SomeEnum.ONE);

            Assert.AreEqual(2, instanceList.Count);
            Assert.AreNotSame(instanceList [0], instanceList [1]);
        }
예제 #9
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;
 }
예제 #10
0
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder> ().ToValue(injectionBinder);
     injectionBinder.Bind <ICommandBinder> ().To <CommandBinder> ().ToSingleton();
     commandBinder = injectionBinder.GetInstance <ICommandBinder> () as ICommandBinder;
 }
예제 #11
0
		public void SetUp()
		{
			injectionBinder = new InjectionBinder();
			injectionBinder.Bind<IInjectionBinder> ().Bind<IInstanceProvider> ().ToValue (injectionBinder);
			injectionBinder.Bind<ICommandBinder> ().To<CommandBinder> ().ToSingleton ();
			commandBinder = injectionBinder.GetInstance<ICommandBinder> ();
		}
예제 #12
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;
 }
예제 #13
0
        public override IState PopulateModel(IInjectionBinder injectionBinder)
        {
            var state = injectionBinder.GetInstance <IState>(GameContextKeys.NewInstance);

            state.Identifier = _id;

            return(state);
        }
 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;
        }
예제 #16
0
        public override ICity PopulateModel(IInjectionBinder injectionBinder)
        {
            var city = injectionBinder.GetInstance <ICity>(GameContextKeys.NewInstance);

            city.Identifier = _id;
            city.Position   = position;
            var stateManager = injectionBinder.GetInstance <BaseIdentifiableManager <IState> >();
            var stateModel   = stateManager[state];

            if (stateModel == null)
            {
                Debug.Log("Could not find an existing State " + stateModel + "for city " + _id);
            }

            city.State = stateModel;

            return(city);
        }
		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;
		}
예제 #18
0
        public override IResource PopulateModel(IInjectionBinder injectionBinder)
        {
            var resource = injectionBinder.GetInstance <IResource>(GameContextKeys.NewInstance);

            resource.Identifier = _id;
            resource.BasePrice  = base_price;

            return(resource);
        }
예제 #19
0
        public T Create <T>(Type type) where T : ControllerBase
        {
            var controller = (T)_injectionBinder.GetInstance(type);

            if (controller == null)
            {
                throw new ControllerCreationException(type);
            }

            return(controller);
        }
예제 #20
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();
        }
예제 #21
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>();
		}
예제 #22
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>();
        }
예제 #23
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 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);
        }
        public void TestSequence()
        {
            //CommandWithInjection requires an ISimpleInterface
            injectionBinder.Bind <ISimpleInterface>().To <SimpleInterfaceImplementer> ().ToSingleton();

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

            TestDelegate testDelegate = delegate
            {
                commandBinder.ReactTo(SomeEnum.ONE);
            };

            //That the exception is thrown demonstrates that the last command ran
            NotImplementedException ex = Assert.Throws <NotImplementedException> (testDelegate);

            Assert.NotNull(ex);

            //That the value is 100 demonstrates that the first command ran
            ISimpleInterface instance = injectionBinder.GetInstance <ISimpleInterface>() as ISimpleInterface;

            Assert.AreEqual(100, instance.intValue);
        }
예제 #26
0
    private void ListBindingsFor(IInjectionBinder binder, ICommandBinder commandBinder)
    {
        EditorGUI.indentLevel++;
        List <object> printedCommandBindings = new List <object>();

        binder.IterateAllBindings(
            (key, name, binding) => {
            List <object> boundValues = new List <object>();
            if (binding.value != null)
            {
                boundValues.Add(binding.value);
            }

            IBinding commandBinding = null;
            if (commandBinder != null)
            {
                Assert.IsTrue(key is Type);
                object boundValue = binder.GetInstance(key as Type, name);
                if (boundValue != null)
                {
                    commandBinding = commandBinder.GetBinding(boundValue, name);
                    if (commandBinding != null && commandBinding.value != null)
                    {
                        Assert.IsTrue(commandBinding.value is object[]);
                        boundValues.AddRange(commandBinding.value as object[]);
                        printedCommandBindings.AddRange(commandBinding.value as object[]);
                    }
                }
            }

            Print(key, name, boundValues);
        }
            );
        if (commandBinder != null)
        {
            commandBinder.IterateAllBindings(
                (key, name, binding) => {
                if (!printedCommandBindings.Contains(binding.value))
                {
                    Print(key, name, new List <object>(binding.value as object[]));
                }
            }
                );
        }
        EditorGUI.indentLevel--;
    }
예제 #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);
     }
 }
예제 #28
0
 private void Start()
 {
     InjectionBinder.GetInstance <ShowMainMenuCmdSig>().Dispatch();
 }
예제 #29
0
        public void TestGetInstance1()
        {
            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ();

            ClassToBeInjected instance = binder.GetInstance(typeof(ClassToBeInjected)) as ClassToBeInjected;

            Assert.IsNotNull(instance);
            Assert.That(instance is ClassToBeInjected);
        }