void ProcessDecoratorInstallers(DiContainer container, bool isBefore)
        {
            if (DecoratorInstallers == null)
            {
                return;
            }

            foreach (var installer in DecoratorInstallers)
            {
                if (installer == null)
                {
                    Log.Warn("Found null installer in composition root");
                    continue;
                }

                if (installer.enabled)
                {
                    container.Inject(installer);

                    if (isBefore)
                    {
                        installer.PreInstallBindings();
                    }
                    else
                    {
                        installer.PostInstallBindings();
                    }
                }
            }
        }
 public AddToExistingGameObjectComponentProvider(
     GameObject gameObject, DiContainer container, Type componentType,
     string concreteIdentifier, List<TypeValuePair> extraArguments)
     : base(container, componentType, concreteIdentifier, extraArguments)
 {
     _gameObject = gameObject;
 }
Exemplo n.º 3
0
 public InjectContext CreateInjectContext(
     DiContainer container, InjectContext currentContext, object targetInstance, string concreteIdentifier)
 {
     return new InjectContext(
         container, MemberType, Identifier, Optional,
         ObjectType, targetInstance, MemberName, currentContext, concreteIdentifier);
 }
 public MonoBehaviourSingletonProviderCreator(
     DiContainer container,
     SingletonRegistry singletonRegistry)
 {
     _singletonRegistry = singletonRegistry;
     _container = container;
 }
Exemplo n.º 5
0
        public void Awake()
        {
            var extraInstallers = new List<IInstaller>();

            if (_staticSettings != null)
            // Static settings are needed if creating a SceneCompositionRoot dynamically
            {
                extraInstallers = _staticSettings.Installers;
                OnlyInjectWhenActive = _staticSettings.OnlyInjectWhenActive;
                ParentNewObjectsUnderRoot = _staticSettings.ParentNewObjectsUnderRoot;
                _staticSettings = null;
            }

            // We always want to initialize GlobalCompositionRoot as early as possible
            GlobalCompositionRoot.Instance.EnsureIsInitialized();

            Assert.IsNull(Container);
            Assert.IsNull(RootFacade);

            Log.Debug("Initializing SceneCompositionRoot in scene '{0}'", this.gameObject.scene.name);
            _container = CreateContainer(
                false, GlobalCompositionRoot.Instance.Container, extraInstallers);

            Log.Debug("SceneCompositionRoot: Finished install phase.  Injecting into scene...");
            InjectObjectsInScene();

            Log.Debug("SceneCompositionRoot: Resolving root IFacade...");
            _rootFacade = _container.Resolve<IFacade>();

            DecoratedScenes.Clear();

            Assert.IsNotNull(Container);
            Assert.IsNotNull(RootFacade);
        }
Exemplo n.º 6
0
        public static void OutputObjectGraphForCurrentScene(
            DiContainer container, IEnumerable<Type> ignoreTypes, IEnumerable<Type> contractTypes)
        {
            string dotFilePath = EditorUtility.SaveFilePanel("Choose the path to export the object graph", "", "ObjectGraph", "dot");

            if (!dotFilePath.IsEmpty())
            {
                ObjectGraphVisualizer.OutputObjectGraphToFile(
                    container, dotFilePath, ignoreTypes, contractTypes);

                var dotExecPath = EditorPrefs.GetString("Zenject.GraphVizDotExePath", "");

                if (dotExecPath.IsEmpty() || !File.Exists(dotExecPath))
                {
                    EditorUtility.DisplayDialog(
                        "GraphViz", "Unable to locate GraphViz.  Please select the graphviz 'dot.exe' file which can be found at [GraphVizInstallDirectory]/bin/dot.exe.  If you do not have GraphViz you can download it at http://www.graphviz.org", "Ok");

                    dotExecPath = EditorUtility.OpenFilePanel("Please select dot.exe from GraphViz bin directory", "", "exe");

                    EditorPrefs.SetString("Zenject.GraphVizDotExePath", dotExecPath);
                }

                if (!dotExecPath.IsEmpty())
                {
                    RunDotExe(dotExecPath, dotFilePath);
                }
            }
        }
Exemplo n.º 7
0
 public PrefabSingletonProvider(
     DiContainer container, Type instanceType, PrefabSingletonLazyCreator creator)
 {
     _creator = creator;
     _container = container;
     _instanceType = instanceType;
 }
 public PrefabSingletonProvider(
     DiContainer container, Type concreteType, PrefabSingletonLazyCreator creator)
 {
     _creator = creator;
     _container = container;
     _concreteType = concreteType;
 }
 public SingletonLazyCreatorByInstance(
     SingletonId id, SingletonProviderMap owner, DiContainer container, object instance)
     : base(id, owner)
 {
     Assert.That(instance != null || container.IsValidating);
     _instance = instance;
 }
Exemplo n.º 10
0
        void ProcessDecoratorInstallers(DiContainer container, bool isBefore)
        {
            if (DecoratorInstallers == null)
            {
                return;
            }

            foreach (var installer in DecoratorInstallers)
            {
                Assert.IsNotNull(installer, "Found null installer in SceneDecoratorContext");

                if (installer.enabled)
                {
                    container.Inject(installer);

                    if (isBefore)
                    {
                        installer.PreInstallBindings();
                    }
                    else
                    {
                        installer.PostInstallBindings();
                    }
                }
            }
        }
Exemplo n.º 11
0
 public EmptyGameObjectProvider(
     DiContainer container, string gameObjectName, string groupName)
 {
     _gameObjectName = gameObjectName;
     _groupName = groupName;
     _container = container;
 }
Exemplo n.º 12
0
        public void FinalizeBinding(DiContainer container)
        {
            Assert.IsNotNull(_subFinalizer,
                "Unfinished binding! Finalizer was not given.");

            _subFinalizer.FinalizeBinding(container);
        }
Exemplo n.º 13
0
        static List<Type> GetDependencies(
            DiContainer container, Type type)
        {
            var dependencies = new List<Type>();

            foreach (var contractType in container.GetDependencyContracts(type))
            {
                List<Type> dependTypes;

                if (contractType.FullName.StartsWith("System.Collections.Generic.List"))
                {
                    var subTypes = contractType.GetGenericArguments();
                    Assert.IsEqual(subTypes.Length, 1);

                    var subType = subTypes[0];
                    dependTypes = container.ResolveTypeAll(subType);
                }
                else
                {
                    dependTypes = container.ResolveTypeAll(contractType);
                    Assert.That(dependTypes.Count <= 1);
                }

                foreach (var dependType in dependTypes)
                {
                    dependencies.Add(dependType);
                }
            }

            return dependencies;
        }
 public StandardSingletonProviderCreator(
     DiContainer container,
     SingletonMarkRegistry markRegistry)
 {
     _markRegistry = markRegistry;
     _container = container;
 }
 public GameObjectSingletonProviderCreator(
     DiContainer container,
     SingletonRegistry singletonRegistry)
 {
     _singletonRegistry = singletonRegistry;
     _container = container;
 }
Exemplo n.º 16
0
 public MethodProviderUntyped(
     Func<InjectContext, object> method,
     DiContainer container)
 {
     _container = container;
     _method = method;
 }
 public InstanceSingletonProviderCreator(
     DiContainer container,
     SingletonRegistry singletonRegistry)
 {
     _singletonRegistry = singletonRegistry;
     _container = container;
 }
Exemplo n.º 18
0
 public SubContainerCreatorByMethod(
     DiContainer container,
     Action<DiContainer> installMethod)
 {
     _installMethod = installMethod;
     _container = container;
 }
Exemplo n.º 19
0
        public void Test1()
        {
            NumInstalls = 0;
            InitTest.WasRun = false;
            TickTest.WasRun = false;
            DisposeTest.WasRun = false;

            var container = new DiContainer();

            container.Bind(typeof(TickableManager), typeof(InitializableManager), typeof(DisposableManager))
                .ToSelf().AsSingle().InheritInSubContainers();

            // This is how you add ITickables / etc. within sub containers
            container.BindAllInterfacesAndSelf<FooKernel>()
                .To<FooKernel>().FromSubContainerResolve().ByMethod(InstallFoo).AsSingle();

            var tickManager = container.Resolve<TickableManager>();
            var initManager = container.Resolve<InitializableManager>();
            var disposeManager = container.Resolve<DisposableManager>();

            Assert.That(!InitTest.WasRun);
            Assert.That(!TickTest.WasRun);
            Assert.That(!DisposeTest.WasRun);

            initManager.Initialize();
            tickManager.Update();
            disposeManager.Dispose();

            Assert.That(InitTest.WasRun);
            Assert.That(TickTest.WasRun);
            Assert.That(DisposeTest.WasRun);
        }
Exemplo n.º 20
0
 public ResolveProvider(
     Type contractType, DiContainer container, object identifier, bool isOptional)
 {
     _contractType = contractType;
     _identifier = identifier;
     _container = container;
     _isOptional = isOptional;
 }
Exemplo n.º 21
0
        public virtual void Setup()
        {
            _container = new DiContainer();
            InstallBindings();

            Validate();
            _container.Inject(this);
        }
Exemplo n.º 22
0
 public SubContainerCreatorByPrefab(
     DiContainer container, IPrefabProvider prefabProvider, string gameObjectName, string groupName)
 {
     _prefabProvider = prefabProvider;
     _groupName = groupName;
     _gameObjectName = gameObjectName;
     _container = container;
 }
Exemplo n.º 23
0
        public void TestValidateDynamicSuccess()
        {
            var container = new DiContainer();

            container.Bind<Foo>().ToSingle();

            Assert.That(container.ValidateObjectGraph<Foo>(typeof(Bar)).IsEmpty());
        }
Exemplo n.º 24
0
 public GameObjectSingletonProvider(
     Type componentType, DiContainer container, string name)
 {
     Assert.That(componentType.DerivesFrom<Component>());
     _componentType = componentType;
     _name = name;
     _container = container;
 }
 public AddToNewGameObjectComponentProvider(
     DiContainer container, Type componentType,
     string concreteIdentifier, List<TypeValuePair> extraArguments, string gameObjectName, string groupName)
     : base(container, componentType, concreteIdentifier, extraArguments)
 {
     _gameObjectName = gameObjectName;
     _groupName = groupName;
 }
 public TypeSingletonLazyCreator(
     SingletonId id, TypeSingletonProviderCreator owner,
     DiContainer container)
 {
     _container = container;
     _id = id;
     _owner = owner;
 }
Exemplo n.º 27
0
        public void TestValidateDynamicFailure2()
        {
            var container = new DiContainer();

            container.Bind<Foo>().ToSingle();

            Assert.That(!container.ValidateObjectGraph<Foo>(typeof(Bar), typeof(string)).IsEmpty());
        }
Exemplo n.º 28
0
        public void TestBindAllInterfacesSimple()
        {
            var container = new DiContainer();

            container.Bind(x => x.AllInterfaces()).To<Foo>();

            Assert.That(container.Resolve<IFoo>() is Foo);
            Assert.That(container.Resolve<IBar>() is Foo);
        }
        public MonoBehaviourSingletonProvider(
            Type componentType, DiContainer container, GameObject gameObject)
        {
            Assert.That(componentType.DerivesFrom<Component>());

            _gameObject = gameObject;
            _componentType = componentType;
            _container = container;
        }
Exemplo n.º 30
0
        public void TestBasicFailure()
        {
            var container = new DiContainer();

            container.Bind<IFoo>().ToSingle<Foo>();
            //container.Bind<Bar>().ToSingle();

            Assert.That(!container.ValidateResolve<IFoo>().IsEmpty());
        }
Exemplo n.º 31
0
 public static IList ResolveAll(this DiContainer container, Type contractType)
 {
     return(container.ResolveAll(contractType, null));
 }
Exemplo n.º 32
0
 public static TContract Resolve <TContract>(this DiContainer container, InjectContext context)
 {
     Assert.IsEqual(context.MemberType, typeof(TContract));
     return((TContract)container.Resolve(context));
 }
Exemplo n.º 33
0
 public Lazy(DiContainer container, InjectContext context)
 {
     _container = container;
     _context   = context;
 }
Exemplo n.º 34
0
 public static object Resolve(this DiContainer container, Type contractType, string identifier)
 {
     return(container.Resolve(new InjectContext(container, contractType, identifier)));
 }
Exemplo n.º 35
0
 public static IEnumerable <Type> GetDependencyContracts <TContract>(this DiContainer container)
 {
     return(container.GetDependencyContracts(typeof(TContract)));
 }
Exemplo n.º 36
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container, string identifier)
 {
     return(container.ResolveAll <TContract>(identifier, false));
 }
Exemplo n.º 37
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container, bool optional)
 {
     return(container.ResolveAll <TContract>(null, optional));
 }
Exemplo n.º 38
0
 public static void Inject(this DiContainer container, object injectable, IEnumerable <object> additional)
 {
     container.Inject(injectable, additional, false);
 }
Exemplo n.º 39
0
 public static void Inject(this DiContainer container, object injectable, InjectContext context)
 {
     container.Inject(
         injectable, Enumerable.Empty <object>(), false,
         TypeAnalyzer.GetInfo(injectable.GetType()), context);
 }
Exemplo n.º 40
0
 public static void Inject(this DiContainer container, object injectable, IEnumerable <object> additional, bool shouldUseAll)
 {
     container.Inject(
         injectable, additional, shouldUseAll,
         TypeAnalyzer.GetInfo(injectable.GetType()), new InjectContext(container, injectable.GetType(), null));
 }
Exemplo n.º 41
0
 public static void Inject(this DiContainer container, object injectable, IEnumerable <object> additional, InjectContext context)
 {
     container.Inject(injectable, additional, false,
                      TypeAnalyzer.GetInfo(injectable.GetType()), context);
 }
Exemplo n.º 42
0
 public GenericBinder(
     DiContainer container, string identifier)
     : base(container, typeof(TContract), identifier)
 {
 }
Exemplo n.º 43
0
 public FactoryFromBinder(
     DiContainer container, BindInfo bindInfo, FactoryBindInfo factoryBindInfo)
     : base(container, typeof(TContract), bindInfo, factoryBindInfo)
 {
 }
        public override object GetInstance(InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(context.MemberType));

            if (_instance == null)
            {
                Assert.That(!_container.AllowNullBindings,
                            "Tried to instantiate a MonoBehaviour with type '{0}' during validation. Object graph: {1}", _componentType, DiContainer.GetCurrentObjectGraph());

                _instance = _gameObject.AddComponent(_componentType);
                Assert.That(_instance != null);

                InjectionHelper.InjectMonoBehaviour(_container, _instance);
            }

            return(_instance);
        }
Exemplo n.º 45
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container, InjectContext context)
 {
     Assert.IsEqual(context.MemberType, typeof(TContract));
     return((List <TContract>)container.ResolveAll(context));
 }
Exemplo n.º 46
0
 public static void Inject(this DiContainer container, object injectable)
 {
     container.Inject(injectable, Enumerable.Empty <object>());
 }
Exemplo n.º 47
0
        public static List <TContract> ResolveAll <TContract>(this DiContainer container, string identifier, bool optional)
        {
            var context = new InjectContext(container, typeof(TContract), identifier, optional);

            return(container.ResolveAll <TContract>(context));
        }
Exemplo n.º 48
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container)
 {
     return(container.ResolveAll <TContract>((string)null));
 }
Exemplo n.º 49
0
        private void GameSceneSceneWasLoaded(ScenesTransitionSetupDataSO a, Zenject.DiContainer b)
        {
            // Prevent firing this event when returning to menu
            Resources.FindObjectsOfTypeAll <GameScenesManager>().FirstOrDefault().transitionDidFinishEvent -= GameSceneSceneWasLoaded;

            var pauseManager = Resources.FindObjectsOfTypeAll <GamePause>().FirstOrDefault();

            Debug.Log(pauseManager);
            pauseManager.didResumeEvent += delegate() { InvokeAll(songUnpaused); };
            pauseManager.didPauseEvent  += delegate() { InvokeAll(songPaused); };

            var scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();

            scoreController.noteWasCutEvent          += delegate(NoteData noteData, NoteCutInfo noteCutInfo, int multiplier) { InvokeAll(noteWasCut, noteData, noteCutInfo, multiplier); };
            scoreController.noteWasMissedEvent       += delegate(NoteData noteData, int multiplier) { InvokeAll(noteWasMissed, noteData, multiplier); };;
            scoreController.multiplierDidChangeEvent += delegate(int multiplier, float progress) { InvokeAll(multiplierDidChange, multiplier, progress); if (multiplier > 1 && progress < 0.1f)
                                                                                                   {
                                                                                                       InvokeAll(multiplierDidIncrease, multiplier);
                                                                                                   }
            };
            scoreController.comboDidChangeEvent             += delegate(int combo) { InvokeAll(comboDidChange, combo); };
            scoreController.comboBreakingEventHappenedEvent += delegate() { InvokeAll(comboDidBreak); };
            scoreController.scoreDidChangeEvent             += delegate(int rawScore, int modifiedScore) { InvokeAll(scoreDidChange, rawScore, modifiedScore); };

            var saberCollisionManager = Resources.FindObjectsOfTypeAll <ObstacleSaberSparkleEffectManager>().FirstOrDefault();

            saberCollisionManager.sparkleEffectDidStartEvent += delegate(SaberType saber) { InvokeAll(sabersStartCollide, saber); };
            saberCollisionManager.sparkleEffectDidEndEvent   += delegate(SaberType saber) { InvokeAll(sabersEndCollide, saber); };

            var gameEnergyCounter = Resources.FindObjectsOfTypeAll <GameEnergyCounter>().FirstOrDefault();

            gameEnergyCounter.gameEnergyDidReach0Event += delegate() { InvokeAll(energyReachedZero); };
            gameEnergyCounter.gameEnergyDidChangeEvent += delegate(float energy) { InvokeAll(energyDidChange, energy); };

            var beatmapObjectCallbackController = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().FirstOrDefault();

            beatmapObjectCallbackController.beatmapEventDidTriggerEvent += delegate(BeatmapEventData songEvent) { InvokeAll(beatmapEvent, songEvent); };

            var transitionSetup = Resources.FindObjectsOfTypeAll <StandardLevelScenesTransitionSetupDataSO>().FirstOrDefault();

            transitionSetup.didFinishEvent += delegate(StandardLevelScenesTransitionSetupDataSO data, LevelCompletionResults results)
            {
                switch (results.levelEndStateType)
                {
                case LevelCompletionResults.LevelEndStateType.Cleared:
                    InvokeAll(levelCleared, data, results);
                    break;

                case LevelCompletionResults.LevelEndStateType.Failed:
                    InvokeAll(levelFailed, data, results);
                    break;

                default:
                    switch (results.levelEndAction)
                    {
                    case LevelCompletionResults.LevelEndAction.Quit:
                        InvokeAll(levelQuit, data, results);
                        break;

                    case LevelCompletionResults.LevelEndAction.Restart:
                        InvokeAll(levelRestarted, data, results);
                        break;
                    }
                    break;
                }
                ;
            };

            InvokeAll(gameSceneLoaded);
        }
Exemplo n.º 50
0
 public static bool HasBinding <TContract>(this DiContainer container)
 {
     return(container.HasBinding <TContract>(null));
 }
Exemplo n.º 51
0
 public static void BindAllInterfacesToSingle <TConcrete>(this DiContainer container)
     where TConcrete : class
 {
     container.BindAllInterfacesToSingle(typeof(TConcrete));
 }
Exemplo n.º 52
0
 public static object TryResolve(this DiContainer container, Type contractType)
 {
     return(container.TryResolve(contractType, null));
 }
Exemplo n.º 53
0
 public static bool HasBinding <TContract>(this DiContainer container, string identifier)
 {
     return(container.HasBinding(
                new InjectContext(container, typeof(TContract), identifier)));
 }
Exemplo n.º 54
0
 public static IEnumerable <ZenjectResolveException> ValidateResolve <TContract>(this DiContainer container, string identifier)
 {
     return(container.ValidateResolve(new InjectContext(container, typeof(TContract), identifier)));
 }
Exemplo n.º 55
0
        public static IList ResolveAll(this DiContainer container, Type contractType, string identifier, bool optional)
        {
            var context = new InjectContext(container, contractType, identifier, optional);

            return(container.ResolveAll(context));
        }
Exemplo n.º 56
0
 public static IList ResolveAll(this DiContainer container, Type contractType, bool optional)
 {
     return(container.ResolveAll(contractType, null, optional));
 }
Exemplo n.º 57
0
 public static bool Unbind <TContract>(this DiContainer container)
 {
     return(container.Unbind <TContract>(null));
 }
Exemplo n.º 58
0
 public static IList ResolveAll(this DiContainer container, Type contractType, string identifier)
 {
     return(container.ResolveAll(contractType, identifier, false));
 }
Exemplo n.º 59
0
 public static object Resolve(this DiContainer container, Type contractType)
 {
     return(container.Resolve(new InjectContext(container, contractType, null)));
 }
Exemplo n.º 60
0
 public FactoryToChoiceIdBinder(
     DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo)
     : base(bindContainer, bindInfo, factoryBindInfo)
 {
 }