public BindingConditionSetter ToInstance(Type concreteType, object instance) { if (ZenUtil.IsNull(instance) && !Container.IsValidating) { string message; if (ContractType == concreteType) { message = "Received null instance during Bind command with type '{0}'".Fmt(ContractType.Name()); } else { message = "Received null instance during Bind command when binding type '{0}' to '{1}'".Fmt(ContractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } if (!ZenUtil.IsNull(instance) && !instance.GetType().DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } return(ToProvider(new InstanceProvider(concreteType, instance))); }
protected BindingConditionSetter ToSingleInstance(Type concreteType, string concreteIdentifier, object instance) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } if (ZenUtil.IsNull(instance) && !Container.IsValidating) { string message; if (ContractType == concreteType) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(ContractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(ContractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(concreteIdentifier, concreteType, instance))); }
public BindingConditionSetter ToSingleInstance <TConcrete>(TConcrete instance, string identifier) { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == concreteType) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(identifier, instance))); }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 29 + (this.Identifier == null ? 0 : this.Identifier.GetHashCode()); hash = hash * 29 + (ZenUtil.IsNull(this.Prefab) ? 0 : this.Prefab.GetHashCode()); return(hash); } }
// Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToTransientPrefab <TConcrete>(GameObject prefab) where TConcrete : Component, TContract { // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(typeof(TConcrete).Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab <TConcrete>(_container, prefab))); }
// Note that concreteType here could be an interface as well public BindingConditionSetter ToSinglePrefab(Type concreteType, string concreteIdentifier, GameObject prefab) { Assert.That(concreteType.DerivesFromOrEqual <TContract>()); if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException( "Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } var prefabSingletonMap = _container.Resolve <PrefabSingletonProviderMap>(); return(ToProvider( prefabSingletonMap.CreateProvider(concreteIdentifier, concreteType, prefab))); }
public BindingConditionSetter ToTransientPrefab(Type concreteType, GameObject prefab) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab(concreteType, prefab))); }
// Note that concreteType here could be an interface as well public BindingConditionSetter ToSinglePrefab( Type concreteType, string concreteIdentifier, GameObject prefab) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException( "Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider( Container.SingletonProviderCreator.CreateProviderFromPrefab(concreteIdentifier, concreteType, prefab))); }
// Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToTransientFromPrefab <TConcrete>(GameObject prefab) where TConcrete : Component { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab) && !_container.AllowNullBindings) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab <TConcrete>(_container, prefab))); }
public BindingConditionSetter ToSingleInstance <TConcrete>(string concreteIdentifier, TConcrete instance) where TConcrete : TContract { if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == typeof(TConcrete)) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), typeof(TConcrete).Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(concreteIdentifier, instance))); }
public BindingConditionSetter ToInstance <TConcrete>(TConcrete instance) where TConcrete : TContract { if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == typeof(TConcrete)) { message = "Received null instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), typeof(TConcrete).Name()); } throw new ZenjectBindException(message); } return(ToProvider(new InstanceProvider(typeof(TConcrete), instance))); }
public BindingConditionSetter ToSingleFromPrefab <TConcrete>(string identifier, GameObject prefab) where TConcrete : Component { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab) && !_container.AllowNullBindings) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } var prefabSingletonMap = _container.Resolve <PrefabSingletonProviderMap>(); return(ToProvider( prefabSingletonMap.CreateProvider(identifier, typeof(TConcrete), prefab))); }