static void InjectFromResolve( InjectableInfo injectInfo, DiContainer container, object targetInstance) { var valueObj = container.Resolve(injectInfo, targetInstance); if (valueObj == null && !container.AllowNullBindings) { // Do not change if optional // Since it may have some hard coded value Assert.That(injectInfo.Optional); // Should have thrown resolve exception otherwise } else { Assert.IsNotNull(injectInfo.Setter); injectInfo.Setter(targetInstance, valueObj); } }
public override object GetInstance(Type contractType, InjectContext context) { Assert.That(_componentType.DerivesFromOrEqual(contractType)); if (_instance == null) { if (_instantiator == null) { _instantiator = _container.Resolve <GameObjectInstantiator>(); } // 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); }
public TContract Create(params object[] constructorArgs) { if (_instantiator == null) { _instantiator = _container.Resolve <GameObjectInstantiator>(); } var gameObj = _instantiator.Instantiate(_prefab, constructorArgs); var component = gameObj.GetComponentInChildren <TContract>(); if (component == null) { throw new ZenjectResolveException( "Could not find component '{0}' when creating game object from prefab".With(typeof(TContract).Name())); } return(component); }
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); }
public override object GetInstance(Type contractType, InjectContext context) { return(_container.Resolve(contractType, context)); }
public GameObjectInstantiator(DiContainer container) { _container = container; _compRoot = container.Resolve <CompositionRoot>(); }