コード例 #1
0
ファイル: TypeBinder.cs プロジェクト: Avatarchik/OutOfTheBox
        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)));
        }
コード例 #2
0
ファイル: BinderUntyped.cs プロジェクト: hexgrimm/Zenject
        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 (UnityUtil.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)));
        }
コード例 #3
0
        public BindingConditionSetter ToSingleInstance <TConcrete>(string singletonIdentifier, TConcrete instance)
            where TConcrete : TContract
        {
            if (UnityUtil.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(singletonIdentifier, instance)));
        }