Beispiel #1
0
        private void Bind(ImplicitBindingVO toBind)
        {
            //We do not check for the existence of a binding. Because implicit bindings are weak bindings, they are overridden automatically by other implicit bindings
            //Therefore, ImplementedBy will be overriden by an Implements to that interface.

            IInjectionBinding binding = injectionBinder.Bind(toBind.BindTypes.First());

            binding.Weak();            //SDM2014-0120: added as part of cross-context implicit binding fix (moved from below)

            for (int i = 1; i < toBind.BindTypes.Count; i++)
            {
                Type bindType = toBind.BindTypes.ElementAt(i);
                binding.Bind(bindType);
            }

            binding = toBind.ToType != null?
                      binding.To(toBind.ToType).ToName(toBind.Name).ToSingleton() :
                          binding.ToName(toBind.Name).ToSingleton();

            if (toBind.IsCrossContext)             //Bind this to the cross context injector
            {
                binding.CrossContext();
            }

            //binding.Weak();//SDM2014-0120: removed as part of cross-context implicit binding fix (moved up higher)
        }
Beispiel #2
0
        /// <summary>
        /// 绑定值类型到接口
        /// </summary>
        /// <typeparam name="I">接口类型</typeparam>
        /// <typeparam name="V">值类型</typeparam>
        /// <param name="crossContext">是否跨域</param>
        protected void BindValue <I, V>(bool crossContext = false)
        {
            IInjectionBinding binding = injectionBinder.Bind <I>().To <V>().ToSingleton();

            if (crossContext)
            {
                binding.CrossContext();
            }
        }
Beispiel #3
0
    public void BindCrossContext(object key)
    {
        IInjectionBinding binding = injectionBinder.GetBinding(key);

        if (binding == null)
        {
            throw new Exception("Object " + key.ToString() + " not yet bound, cannot make cross context");
        }

        binding.CrossContext();
    }
Beispiel #4
0
    public IInjectionBinding BindSignalCrossContext <S>()
    {
        IInjectionBinding binding = injectionBinder.GetBinding <S>() ?? injectionBinder.Bind <S>();

        binding.CrossContext();

        object instance = injectionBinder.GetInstance <S>();

        binding.ToValue(instance);

        return(binding);
    }
Beispiel #5
0
        /// <summary>
        /// 绑定值类型到指定值
        /// </summary>
        /// <typeparam name="V">类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="name">绑定名称</param>
        /// <param name="crossContext">是否跨域</param>
        protected void BindValue <V>(V value, string name = null, bool crossContext = false)
        {
            IInjectionBinding binding = injectionBinder.Bind <V>().ToValue(value);

            if (!string.IsNullOrEmpty(name))
            {
                binding.ToName(name);
            }
            if (crossContext)
            {
                binding.CrossContext();
            }
        }
Beispiel #6
0
    public virtual IInjectionBinding Bind <Type>(bool singleton = false, bool crosscontext = false)
    {
        IInjectionBinding binding = injectionBinder.Bind <Type>();

        if (singleton)
        {
            binding = binding.ToSingleton();
        }
        if (crosscontext)
        {
            binding = binding.CrossContext();
        }
        return(binding);
    }
        /// Additional options: ToSingleton, CrossContext
        override protected IBinding addRuntimeOptions(IBinding b, List <object> options)
        {
            base.addRuntimeOptions(b, options);
            IInjectionBinding binding = b as IInjectionBinding;

            if (options.IndexOf("ToSingleton") > -1)
            {
                binding.ToSingleton();
            }
            if (options.IndexOf("CrossContext") > -1)
            {
                binding.CrossContext();
            }
            IEnumerable <Dictionary <string, object> > dict = options.OfType <Dictionary <string, object> > ();

            if (dict.Any())
            {
                Dictionary <string, object> supplyToDict = dict.First(a => a.Keys.Contains("SupplyTo"));
                if (supplyToDict != null)
                {
                    foreach (KeyValuePair <string, object> kv in supplyToDict)
                    {
                        if (kv.Value is string)
                        {
                            Type valueType = Type.GetType(kv.Value as string);
                            binding.SupplyTo(valueType);
                        }
                        else
                        {
                            List <object> values = kv.Value as List <object>;
                            for (int a = 0, aa = values.Count; a < aa; a++)
                            {
                                Type valueType = Type.GetType(values[a] as string);
                                binding.SupplyTo(valueType);
                            }
                        }
                    }
                }
            }

            return(binding);
        }