Example #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)
        }
Example #2
0
        public static IInjectionBinding BindType <T> (Type type, object name = null)
        {
            IInjectionBinding binding = Context.injectionBinder.Bind <T> ().To(type).ToSingleton();

            if (name != null)
            {
                binding.ToName(name);
            }
            return(binding);
        }
Example #3
0
        public static IInjectionBinding BindValue <T> (T value, object name = null)
        {
            IInjectionBinding binding = Context.injectionBinder.Bind <T> ().ToValue(value);

            if (name != null)
            {
                binding.ToName(name);
            }
            return(binding);
        }
Example #4
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();
            }
        }