Example #1
0
 public MVCSExtension(MediationMode mediationMode)
 {
     CommandBinder   = new CommandBinder();
     EventDispatcher = new EventDispatcherWithCommandProcessing((CommandBinder)CommandBinder);
     InjectionBinder = new InjectionBinder();
     MediationBinder = new MediationBinder(mediationMode, InjectionBinder);
 }
Example #2
0
        void Start()
        {
            Dispatcher = new EventDispatcher();
            //Dispatcher.Bind("Hello").To(onHelloCallback).To(onHelloCallback2);
            Dispatcher.AddListener("Hello", onHelloCallback);
            Dispatcher.AddListener("Hello", onHelloCallback2);

            //Dispatcher.Bind("Hello").To(onHelloCallback2);

            CustomEvent evtObj = new CustomEvent()
            {
                target = null
            };

            Dispatcher.Trigger("Hello", evtObj);

            InjectionBinder injectionBinder = new InjectionBinder();

            injectionBinder.Bind <EventDispatcher>().ToValue(Dispatcher).ToName("dispatcher1").ToInject(false);
            injectionBinder.Bind <EventDispatcher>().ToValue(new EventDispatcher()).ToName("dispatcher2").ToInject(false);

            AABB aabb = new AABB();

            injectionBinder.injector.Inject(aabb);


            int b = 1;
        }
Example #3
0
        private void InstallModules()
        {
            InjectionBinder.Bind <ModuleInitializerHolder>().ToInstance(new ModuleInitializerHolder(modules));

            foreach (var installer in modules)
            {
                InjectionBinder.Inject(installer);
                installer.ExecuteAfterBindings(InjectionBinder, CommandInjector);
            }
        }
Example #4
0
 private void UnbindParams(params Tuple <object, Type>[] bindparamsWithType)
 {
     if (bindparamsWithType != null)
     {
         foreach (var param in bindparamsWithType)
         {
             InjectionBinder.Unbind(param.Item2);
         }
     }
 }
Example #5
0
 private void UnbindParams(params object[] bindparams)
 {
     if (bindparams != null)
     {
         foreach (var param in bindparams)
         {
             InjectionBinder.Unbind(param.GetType());
         }
     }
 }
Example #6
0
        /*
         * Context.
         */

        private void OnContextStarting()
        {
            InjectionBinder.ForEachBinding(binding =>
            {
                if (binding.ToConstructOnStart)
                {
                    InjectionBinder.GetInstance(binding);
                }
            });
        }
Example #7
0
        public void Setup()
        {
            injectionBinder = new InjectionBinder();
            injectionBinder.Bind <IInstanceProvider>().Bind <IInjectionBinder>().ToValue(injectionBinder);
            injectionBinder.Bind <OverriddenSignalMediationBinder>().ToSingleton();
            injectionBinder.Bind <OneArgSignal>().ToSingleton();

            binder = injectionBinder.GetInstance <OverriddenSignalMediationBinder>();            //get an injected version to make our life easier

            injectionBinder.Bind <SignalMediator>().ToSingleton();
        }
Example #8
0
        void Start()
        {
            InjectionBinder injectionBinder = new InjectionBinder();

            injectionBinder.Bind <IEnemy>().To <Boss>().ToName(EnemyType.ADVANCE);
            injectionBinder.Bind <IEnemy>().To <Monster>().ToName(EnemyType.BASIC);
            injectionBinder.Bind <EnemyManager>().To <EnemyManager>().ToSingleton();

            EnemyManager manager = injectionBinder.GetInstance <EnemyManager>();
            int          a       = 1;
        }
Example #9
0
 public void Init()
 {
     view = new MockView();
     injector = new InjectionBinder();
     injector.Bind<GameObject>().ToName(ContextKeys.CONTEXT_VIEW).ToValue(new GameObject());
     injector.Bind<MockView>().ToValue(view);
     injector.Bind<MockMediator>().ToSingleton();
     injector.Bind<IInjectionBinder>().ToValue(injector);
     mediator = injector.GetInstance<MockMediator>();
     mediator.OnRegister();
 }
Example #10
0
        public override void Dispose()
        {
            Context.OnStarting -= OnContextStarting;
            Context.OnStarted  -= OnContextStarted;
            Context.OnQuitting -= OnContextQuitting;
            Context.OnStopped  -= OnContextStopped;

            Context.OnModuleConstructing -= OnModuleConstructing;
            Context.OnModuleDisposing    -= OnModuleDisposing;

            CommandBinder.UnbindAll();
            InjectionBinder.UnbindAll();
        }
Example #11
0
        void Start()
        {
            InjectionBinder injectionBinder = new InjectionBinder();

            injectionBinder.Bind <IInstanceProvider>().Bind <IInjectionBinder>().ToValue(injectionBinder);
            injectionBinder.Bind <ICommandBinder>().To <CommandBinder>().ToSingleton();
            ICommandBinder commandBinder = injectionBinder.GetInstance <ICommandBinder>();

            commandBinder.Bind <Command1>().To <Command1>();
            commandBinder.Bind <Command2>().To <Command2>();

            int a = 1;
        }
Example #12
0
        void Start()
        {
            InjectionBinder injectionBinder = new InjectionBinder();

            injectionBinder.Bind <IEnemy>().To <Boss>().ToName(EnemyType.ADVANCE);
            injectionBinder.Bind <IEnemy>().To <Monster>().ToName(EnemyType.BASIC);
            injectionBinder.Bind <EnemyManager>().To <EnemyManager>().ToSingleton();
            //injectionBinder.ReflectAll();

            EnemyManager manager = injectionBinder.GetInstance <EnemyManager>();

            //List < object >
            ////EnemyManager manager = new EnemyManager();
            ////injectionBinder.injector.Inject(manager);
            //int a = 1;
        }
Example #13
0
        public void PostConstruct()
        {
            #if UNITY_EDITOR
            InjectionBinder.Bind <INotificationsController>().To <Impl.NotificationsControllerEditor>().AsSingleton();
            #elif UNITY_ANDROID
            InjectionBinder.Bind <INotificationsController>().To <Impl.NotificationsControllerAndroid>().AsSingleton();
            #elif UNITY_IOS
            InjectionBinder.Bind <INotificationsController>().To <Impl.NotificationsControllerIOS>().AsSingleton();
            #endif

            CommandBinder.Bind(AppEvent.Pause).To <NotificationsClearCommand>();

            #if UNITY_ANDROID && !UNITY_EDITOR
            CommandBinder.Bind(AppEvent.Focus).To <NotificationsCleanDisplayedCommand>();
            #endif

            CommandBinder.Bind(NotificationsEvent.Initialized).To <NotificationsInitializedCommand>();
        }
Example #14
0
        public override void Initialize()
        {
            Context.OnStarting += OnContextStarting;
            Context.OnStarted  += OnContextStarted;
            Context.OnQuitting += OnContextQuitting;
            Context.OnStopped  += OnContextStopped;

            Context.OnModuleConstructing += OnModuleConstructing;
            Context.OnModuleDisposing    += OnModuleDisposing;

            InjectionBinder.Bind <IContext>().ToValue(Context);
            InjectionBinder.Bind <IEventBus>().To <EventBus>().AsSingleton();
            InjectionBinder.Bind <IEventDispatcher>().ToValue(EventDispatcher).ConstructValue();
            InjectionBinder.Bind <IEventMap>().ToProvider <EventMapProvider>();
            InjectionBinder.Bind <IInjectionBinder>().ToValue(InjectionBinder);
            InjectionBinder.Bind <ICommandBinder>().ToValue(CommandBinder).ConstructValue();
            InjectionBinder.Bind <IMediationBinder>().ToValue(MediationBinder);
        }
Example #15
0
		public void TestALotOfInstances ()
		{
			IInjectionBinder injectionBinder = new InjectionBinder ();
			injectionBinder.Bind<ClassToBeInjected> ().To<ClassToBeInjected> ();
			injectionBinder.Bind<int> ().To (42);
			injectionBinder.Bind<InjectableSuperClass> ().To<InjectableDerivedClass>();

			Stopwatch stopwatch = new Stopwatch ();
			stopwatch.Start ();

			int aa = 1000;
			for (int a = 0; a < aa; a++)
			{
				injectionBinder.GetInstance<InjectableSuperClass> ();
			}

			stopwatch.Stop ();

			//Uncomment this if you want to run the speed test.
			//throw new InjectionException ("The test took " + stopwatch.ElapsedMilliseconds + " ms.", InjectionExceptionType.NO_REFLECTOR);
		}
Example #16
0
 /// Map the relationships between the Binders.
 /// Although you can override this method, it is recommended
 /// that you provide all your application bindings in `mapBindings()`.
 protected override void addCoreComponents()
 {
     injectionBinder = new InjectionBinder();
     injectionBinder.Bind <IInjectionBinder>().ToValue(injectionBinder);
     injectionBinder.Bind <IContext>().ToValue(this).ToName(ContextKeys.CONTEXT);
     injectionBinder.Bind <ICommandBinder>().To <EventCommandBinder>().ToSingleton();
     //This binding is for local dispatchers
     injectionBinder.Bind <IEventDispatcher>().To <EventDispatcher>();
     //This binding is for the common system bus
     injectionBinder.Bind <IEventDispatcher>().To <EventDispatcher>().ToSingleton().ToName(ContextKeys.CONTEXT_DISPATCHER);
     injectionBinder.Bind <IMediationBinder>().To <MediationBinder>().ToSingleton();
     injectionBinder.Bind <ISequencer>().To <EventSequencer>().ToSingleton();
     if (firstContext == this)
     {
         injectionBinder.Bind <IEventDispatcher>().To <EventDispatcher>().ToSingleton().ToName(ContextKeys.CROSS_CONTEXT_DISPATCHER);
     }
     else if (crossContextDispatcher != null)
     {
         injectionBinder.Bind <IEventDispatcher>().ToValue(crossContextDispatcher).ToName(ContextKeys.CROSS_CONTEXT_DISPATCHER);
     }
 }
Example #17
0
        public void TestALotOfInstances()
        {
            IInjectionBinder injectionBinder = new InjectionBinder();

            injectionBinder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ();
            injectionBinder.Bind <int> ().To(42);
            injectionBinder.Bind <InjectableSuperClass> ().To <InjectableDerivedClass>();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            int aa = 1000;

            for (int a = 0; a < aa; a++)
            {
                injectionBinder.GetInstance <InjectableSuperClass> ();
            }

            stopwatch.Stop();

            //Uncomment this if you want to run the speed test.
            //throw new InjectionException ("The test took " + stopwatch.ElapsedMilliseconds + " ms.", InjectionExceptionType.NO_REFLECTOR);
        }
 public void SetUp()
 {
     injectionBinder = new InjectionBinder();
     mediationBinder = new TestMediationBinder();
     mediationBinder.injectionBinder = injectionBinder;
 }
Example #19
0
 private void OnModuleDisposing(IModule module)
 {
     InjectionBinder.Destroy(module, true);
 }
Example #20
0
        /*
         * Modules.
         */

        private void OnModuleConstructing(IModule module)
        {
            InjectionBinder.Construct(module, true);
        }
Example #21
0
 protected override void Launch()
 {
     InjectionBinder.Get <StartApp>().Dispatch();
 }
Example #22
0
    private void DrawModels()
    {
        if (!Application.isPlaying)
        {
            EditorGUILayout.LabelField("Enter Play Mode to view Models.");
            return;
        }

        if (Selection.activeObject == null)
        {
            EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject");
            return;
        }

        GameObject rootGameObject = Selection.activeObject as GameObject;

        if (rootGameObject == null)
        {
            EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject");
            return;
        }

        _inspectedRoot = rootGameObject.GetComponent <RichMVCContextRoot>();
        if (_inspectedRoot == null)
        {
            EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject");
            return;
        }

        SirenixEditorFields.UnityObjectField("Inspecting", _inspectedRoot, typeof(RichMVCContextRoot), true);
        SirenixEditorGUI.DrawThickHorizontalSeperator(5f, 5f, 5f);

        CrossContext context = _inspectedRoot.context as CrossContext;

        EditorGUILayout.Toggle("Context Found", context != null);
        if (context == null)
        {
            return;
        }

        FieldInfo fieldInfo = typeof(CrossContextInjectionBinder).BaseType.GetField("bindings", BindingFlags.Instance | BindingFlags.NonPublic);

        EditorGUILayout.Toggle("Bindings Found", fieldInfo != null);
        if (fieldInfo == null)
        {
            return;
        }

        InjectionBinder injectionBinder = context.injectionBinder as CrossContextInjectionBinder;

        EditorGUILayout.Toggle("InjectionBinder Casted", injectionBinder != null);
        if (injectionBinder == null)
        {
            return;
        }

        SirenixEditorGUI.DrawThickHorizontalSeperator(5f, 5f, 5f);
        SirenixEditorGUI.Title("Bindings", "", TextAlignment.Center, false);
        SirenixEditorGUI.BeginBox();

        object bindings = fieldInfo.GetValue(injectionBinder);
        Dictionary <object, Dictionary <object, IBinding> > bindingDictionaries = (Dictionary <object, Dictionary <object, IBinding> >)bindings;

        if (bindingDictionaries == null)
        {
            return;
        }

        foreach (object mainKey in bindingDictionaries.Keys)
        {
            string typeName;
            if (!(mainKey is Type))
            {
                continue;
            }

            Type mainKeyType = mainKey as Type;

            if (_ignoredTypeList.Contains(mainKeyType))
            {
                continue;
            }

            IBinding binding = injectionBinder.GetBinding(mainKeyType);

            if (binding == null)
            {
                continue;
            }
            SirenixEditorGUI.BeginBox();

            typeName = mainKey.ToString();
            SirenixEditorGUI.Title(mainKeyType.Name, "", TextAlignment.Center, false);

            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            object instance = injectionBinder.GetInstance(mainKeyType);
            if (GUILayout.Button("Inspect", GUILayout.Height(20), GUILayout.Width(80)))
            {
                OdinEditorWindow.InspectObject(instance);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();

            SirenixEditorGUI.EndBox();
            SirenixEditorGUI.DrawHorizontalLineSeperator(2f, 2f, 2f);
        }
        SirenixEditorGUI.EndBox();
    }
Example #23
0
 public void PostConstruct()
 {
     _bus = InjectionBinder.Construct <EventBus>(true);
 }
Example #24
0
 public void PreDestroy()
 {
     InjectionBinder.Destroy(_bus, true);
     _bus = null;
 }
        public override void Execute()
        {
            HashSet <object> instanceSet = new HashSet <object>();

            RichMVCContextRoot[] roots = GameObject.FindObjectsOfType <RichMVCContextRoot>();

            foreach (RichMVCContextRoot root in roots)
            {
                Debug.Log("Adding models of " + root + " to SRDebugger");

                FieldInfo fieldInfo = typeof(CrossContextInjectionBinder).BaseType.GetField("bindings", BindingFlags.Instance | BindingFlags.NonPublic);

                if (fieldInfo == null)
                {
                    return;
                }

                CrossContext context = root.context as CrossContext;

                InjectionBinder injectionBinder = context.injectionBinder as CrossContextInjectionBinder;

                if (injectionBinder == null)
                {
                    return;
                }

                object bindings = fieldInfo.GetValue(injectionBinder);
                Dictionary <object, Dictionary <object, IBinding> > bindingDictionaries = (Dictionary <object, Dictionary <object, IBinding> >)bindings;
                if (bindingDictionaries == null)
                {
                    return;
                }

                foreach (object mainKey in bindingDictionaries.Keys)
                {
                    string typeName;
                    if (!(mainKey is Type))
                    {
                        continue;
                    }

                    Type mainKeyType = mainKey as Type;

                    if (_ignoredTypeList.Contains(mainKeyType))
                    {
                        continue;
                    }

                    IBinding binding = injectionBinder.GetBinding(mainKeyType);

                    if (binding == null)
                    {
                        continue;
                    }

                    typeName = mainKey.ToString();

                    object instance = injectionBinder.GetInstance(mainKeyType);

                    if (instanceSet.Contains(instance))
                    {
                        continue;
                    }

                    Debug.Log("Adding " + instance.ToString());
                    SRDebug.Instance.AddOptionContainer(instance);
                    instanceSet.Add(instance);
                }
            }
        }
		public void SetUp()
		{
			injectionBinder = new InjectionBinder ();
			mediationBinder = new TestMediationBinder ();
			mediationBinder.injectionBinder = injectionBinder;
		}
Example #27
0
 private void OnContextStopped()
 {
     InjectionBinder.GetInstance <IEventDispatcher>().Dispatch(ContextEvent.Stopped);
 }