public static void BindPriority(
            DiContainer container, Type tickableType, int priorityCount)
        {
            Assert.That(tickableType.DerivesFrom <ITickable>(),
                        "Expected type '{0}' to derive from ITickable", tickableType.Name());

            container.Bind <Tuple <Type, int> >().To(
                Tuple.New(tickableType, priorityCount)).WhenInjectedInto <TickableManager>();
        }
Esempio n. 2
0
        public static void BindPriority(
            DiContainer container, Type disposableType, int priorityCount)
        {
            Assert.That(disposableType.DerivesFrom <IDisposable>(),
                        "Expected type '{0}' to derive from IDisposable", disposableType.Name());

            container.Bind <Tuple <Type, int> >().To(
                Tuple.New(disposableType, priorityCount)).WhenInjectedInto <DisposablesHandler>();
        }
Esempio n. 3
0
        static IEnumerable <ZenjectResolveException> ValidateInstallers(CompositionRoot compRoot)
        {
            var container = new DiContainer();

            container.Bind <CompositionRoot>().ToSingle(compRoot);

            foreach (var installer in compRoot.Installers)
            {
                if (installer == null)
                {
                    yield return(new ZenjectResolveException(
                                     "Found null installer in properties of Composition Root"));

                    yield break;
                }

                installer.Container = container;
                container.Bind <IInstaller>().To(installer);
            }

            foreach (var error in ZenUtil.ValidateInstallers(container))
            {
                yield return(error);
            }

            // Also make sure we can fill in all the dependencies in the built-in scene
            foreach (var monoBehaviour in compRoot.GetComponentsInChildren <MonoBehaviour>())
            {
                if (monoBehaviour == null)
                {
                    // Be nice to give more information here
                    Debug.LogWarning("Found null MonoBehaviour in scene");
                    continue;
                }

                foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType()))
                {
                    yield return(error);
                }
            }
        }
Esempio n. 4
0
        void InitContainer()
        {
            _container = new DiContainer();

            // Note: This has to go first
            _container.Bind <CompositionRoot>().To(this);

            if (_extraBindingLookup != null)
            {
                _extraBindingLookup(_container);
                _extraBindingLookup = null;
            }
        }
Esempio n. 5
0
        public static DiContainer CreateContainer(bool allowNullBindings, GameObject gameObj)
        {
            Assert.That(allowNullBindings || gameObj != null);

            var container = new DiContainer();

            container.AllowNullBindings = allowNullBindings;

            container.Bind <IInstaller>().ToSingle <StandardUnityInstaller>();
            container.Bind <GameObject>().To(gameObj)
            .WhenInjectedInto <StandardUnityInstaller>();
            container.InstallInstallers();
            Assert.That(!container.HasBinding <IInstaller>());

            foreach (var installer in GetGlobalInstallers())
            {
                FieldsInjecter.Inject(container, installer);
                container.Bind <IInstaller>().To(installer);
                container.InstallInstallers();
                Assert.That(!container.HasBinding <IInstaller>());
            }

            return(container);
        }
Esempio n. 6
0
        void Register()
        {
            if (Installers.IsEmpty())
            {
                Debug.LogError("No installers found while initializing CompositionRoot");
                return;
            }

            foreach (var installer in Installers)
            {
                // The installers that are part of the scene are monobehaviours
                // and therefore were not created via Zenject and therefore do
                // not have their members injected
                // At the very least they will need the container injected but
                // they might also have some configuration passed from another
                // scene
                FieldsInjecter.Inject(_container, installer);
                _container.Bind <IInstaller>().To(installer);
            }

            ZenUtil.InstallInstallers(_container);
        }
Esempio n. 7
0
 protected static BindingConditionSetter AddBindingInternal <TDerived>(DiContainer container, TKey key)
     where TDerived : TBase
 {
     return(container.Bind <Tuple <TKey, Type> >().To(Tuple.New(key, typeof(TDerived))));
 }
Esempio n. 8
0
 public static void AddBinding <TDerived>(DiContainer container, TKey key)
     where TDerived : TBase
 {
     container.Bind <Tuple <TKey, Type> >().To(Tuple.New(key, typeof(TDerived))).WhenInjectedInto <KeyedFactory <TBase, TKey> >();
 }
Esempio n. 9
0
        public void Setup()
        {
            _container = new DiContainer();

            _container.Bind <TaskUpdater <ITickable> >().ToSingle(new TaskUpdater <ITickable>(t => t.Tick()));
        }
Esempio n. 10
0
 public static void BindTickable <TTickable>(DiContainer container, int priority) where TTickable : ITickable
 {
     container.Bind <ITickable>().ToSingle <TTickable>();
     BindTickablePriority <TTickable>(container, priority);
 }
Esempio n. 11
0
 public static void BindTickablePriority <TTickable>(DiContainer container, int priority)
 {
     container.Bind <Tuple <Type, int> >().To(Tuple.New(typeof(TTickable), priority));
 }