Beispiel #1
0
        object Instantiate(Type contractType)
        {
            if (_createMethod != null)
            {
                return(_createMethod(_container));
            }

            var concreteType = GetTypeToInstantiate(contractType);

            if (!UnityUtil.IsNull(_id.Prefab))
            {
                Assert.That(concreteType.DerivesFrom <Component>(), "Expected '{0}' to derive from 'Component'", concreteType.Name);

                if (_gameObjInstantiator == null)
                {
                    _gameObjInstantiator = _container.Resolve <GameObjectInstantiator>();
                }

                return(_gameObjInstantiator.Instantiate(_id.Type, _id.Prefab));
            }

            if (_instantiator == null)
            {
                _instantiator = _container.Resolve <Instantiator>();
            }

            return(_instantiator.Instantiate(concreteType));
        }
Beispiel #2
0
        public override object GetInstance(Type contractType, InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(contractType));

            if (_instance == null)
            {
                if (_instantiator == null)
                {
                    _instantiator = _container.Resolve <GameObjectInstantiator>();
                }

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

                // We don't use the generic version here to avoid duplicate generic arguments to binder
                _instance = _instantiator.Instantiate(_componentType, _name);
                Assert.That(_instance != null);
            }

            return(_instance);
        }