示例#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();

            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) :
                          binding.ToName(toBind.Name);

            if (toBind.IsSingleton)
            {
                binding.ToSingleton();
            }

            if (toBind.IsCrossContext)             //Bind this to the cross context injector
            {
                binding.CrossContext();
            }
        }
示例#2
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);
    }
        override public ICommandBinding Bind(object value)
        {
            IInjectionBinding binding = injectionBinder.GetBinding(value);
            IBaseSignal       signal  = null;

            if (value is Type)
            {
                if (binding == null)                 //If this isn't injected yet, inject a new one as a singleton
                {
                    binding = injectionBinder.Bind(value) as IInjectionBinding;
                    binding.ToSingleton();
                }
                signal = injectionBinder.GetInstance(value as Type) as IBaseSignal;
            }
            return(base.Bind(signal ?? value));
        }
        /// 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);
        }