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;
 }
Пример #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;
 }
Пример #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);
        }
Пример #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);
                }
            }
        }
Пример #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;
 }
Пример #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();
                    }
                }
            }
        }
Пример #11
0
 public EmptyGameObjectProvider(
     DiContainer container, string gameObjectName, string groupName)
 {
     _gameObjectName = gameObjectName;
     _groupName = groupName;
     _container = container;
 }
Пример #12
0
        public void FinalizeBinding(DiContainer container)
        {
            Assert.IsNotNull(_subFinalizer,
                "Unfinished binding! Finalizer was not given.");

            _subFinalizer.FinalizeBinding(container);
        }
Пример #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;
 }
Пример #16
0
 public MethodProviderUntyped(
     Func<InjectContext, object> method,
     DiContainer container)
 {
     _container = container;
     _method = method;
 }
 public InstanceSingletonProviderCreator(
     DiContainer container,
     SingletonRegistry singletonRegistry)
 {
     _singletonRegistry = singletonRegistry;
     _container = container;
 }
 public SubContainerCreatorByMethod(
     DiContainer container,
     Action<DiContainer> installMethod)
 {
     _installMethod = installMethod;
     _container = container;
 }
Пример #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);
        }
Пример #20
0
 public ResolveProvider(
     Type contractType, DiContainer container, object identifier, bool isOptional)
 {
     _contractType = contractType;
     _identifier = identifier;
     _container = container;
     _isOptional = isOptional;
 }
Пример #21
0
        public virtual void Setup()
        {
            _container = new DiContainer();
            InstallBindings();

            Validate();
            _container.Inject(this);
        }
 public SubContainerCreatorByPrefab(
     DiContainer container, IPrefabProvider prefabProvider, string gameObjectName, string groupName)
 {
     _prefabProvider = prefabProvider;
     _groupName = groupName;
     _gameObjectName = gameObjectName;
     _container = container;
 }
Пример #23
0
        public void TestValidateDynamicSuccess()
        {
            var container = new DiContainer();

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

            Assert.That(container.ValidateObjectGraph<Foo>(typeof(Bar)).IsEmpty());
        }
 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;
 }
Пример #27
0
        public void TestValidateDynamicFailure2()
        {
            var container = new DiContainer();

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

            Assert.That(!container.ValidateObjectGraph<Foo>(typeof(Bar), typeof(string)).IsEmpty());
        }
Пример #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;
        }
Пример #30
0
        public void TestBasicFailure()
        {
            var container = new DiContainer();

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

            Assert.That(!container.ValidateResolve<IFoo>().IsEmpty());
        }
Пример #31
0
 public static IList ResolveAll(this DiContainer container, Type contractType)
 {
     return(container.ResolveAll(contractType, null));
 }
Пример #32
0
 public static TContract Resolve <TContract>(this DiContainer container, InjectContext context)
 {
     Assert.IsEqual(context.MemberType, typeof(TContract));
     return((TContract)container.Resolve(context));
 }
Пример #33
0
 public Lazy(DiContainer container, InjectContext context)
 {
     _container = container;
     _context   = context;
 }
Пример #34
0
 public static object Resolve(this DiContainer container, Type contractType, string identifier)
 {
     return(container.Resolve(new InjectContext(container, contractType, identifier)));
 }
Пример #35
0
 public static IEnumerable <Type> GetDependencyContracts <TContract>(this DiContainer container)
 {
     return(container.GetDependencyContracts(typeof(TContract)));
 }
Пример #36
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container, string identifier)
 {
     return(container.ResolveAll <TContract>(identifier, false));
 }
Пример #37
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container, bool optional)
 {
     return(container.ResolveAll <TContract>(null, optional));
 }
Пример #38
0
 public static void Inject(this DiContainer container, object injectable, IEnumerable <object> additional)
 {
     container.Inject(injectable, additional, false);
 }
Пример #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);
 }
Пример #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));
 }
Пример #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);
 }
Пример #42
0
 public GenericBinder(
     DiContainer container, string identifier)
     : base(container, typeof(TContract), identifier)
 {
 }
Пример #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);
        }
Пример #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));
 }
Пример #46
0
 public static void Inject(this DiContainer container, object injectable)
 {
     container.Inject(injectable, Enumerable.Empty <object>());
 }
Пример #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));
        }
Пример #48
0
 public static List <TContract> ResolveAll <TContract>(this DiContainer container)
 {
     return(container.ResolveAll <TContract>((string)null));
 }
Пример #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);
        }
Пример #50
0
 public static bool HasBinding <TContract>(this DiContainer container)
 {
     return(container.HasBinding <TContract>(null));
 }
Пример #51
0
 public static void BindAllInterfacesToSingle <TConcrete>(this DiContainer container)
     where TConcrete : class
 {
     container.BindAllInterfacesToSingle(typeof(TConcrete));
 }
Пример #52
0
 public static object TryResolve(this DiContainer container, Type contractType)
 {
     return(container.TryResolve(contractType, null));
 }
Пример #53
0
 public static bool HasBinding <TContract>(this DiContainer container, string identifier)
 {
     return(container.HasBinding(
                new InjectContext(container, typeof(TContract), identifier)));
 }
Пример #54
0
 public static IEnumerable <ZenjectResolveException> ValidateResolve <TContract>(this DiContainer container, string identifier)
 {
     return(container.ValidateResolve(new InjectContext(container, typeof(TContract), identifier)));
 }
Пример #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));
        }
Пример #56
0
 public static IList ResolveAll(this DiContainer container, Type contractType, bool optional)
 {
     return(container.ResolveAll(contractType, null, optional));
 }
Пример #57
0
 public static bool Unbind <TContract>(this DiContainer container)
 {
     return(container.Unbind <TContract>(null));
 }
Пример #58
0
 public static IList ResolveAll(this DiContainer container, Type contractType, string identifier)
 {
     return(container.ResolveAll(contractType, identifier, false));
 }
Пример #59
0
 public static object Resolve(this DiContainer container, Type contractType)
 {
     return(container.Resolve(new InjectContext(container, contractType, null)));
 }
Пример #60
0
 public FactoryToChoiceIdBinder(
     DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo)
     : base(bindContainer, bindInfo, factoryBindInfo)
 {
 }