public ReflectiveBinding CreateReflectiveBinding(MethodInfo factory, BindingProviderAttribute attribute)
        {
            var dependencies = new List <BindingPair>();

            if (attribute.DependencyCount > 0)
            {
                var parameters = factory.GetParameters();

                for (int i = 0; i < attribute.DependencyCount; ++i)
                {
                    var type = parameters[i].ParameterType;

                    object name = InnerBindingNames.Empty;

                    if (attribute.DependencieNames.Length > i)
                    {
                        name = attribute.DependencieNames[i];
                    }

                    var duo = new BindingPair(name, type);
                    dependencies.Add(duo);
                }
            }

            var root = new BindingPair(attribute.Name, factory.ReturnType);

            return(new ReflectiveBinding(root, factory, dependencies, attribute.Singleton, attribute.Subcontexts));
        }
Ejemplo n.º 2
0
 public ReflectiveBinding(BindingPair root, MethodInfo factory, IList <BindingPair> dependencies, bool singleton, object[] subcontexts)
 {
     this.Root         = root;
     this.Factory      = factory;
     this.Dependencies = dependencies;
     this.Singleton    = singleton;
     this.Subcontexts  = subcontexts;
 }
        private void AddToContext(IBindingContext root, BindingPair pair, IBinding binding, object[] subcontexts)
        {
            IBindingContext finalBindingContext = root;

            foreach (var contextName in subcontexts)
            {
                finalBindingContext = finalBindingContext.GetSubcontext(contextName);
            }

            finalBindingContext.Unsafe.Bind(pair.name, pair.BindingType).To(binding);
        }
Ejemplo n.º 4
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != typeof(BindingPair))
            {
                return(false);
            }
            BindingPair other = (BindingPair)obj;

            return(name == other.name && BindingType == other.BindingType);
        }
            public ReflectionBindingProvider(MethodInfo factory, BindingProviderAttribute attribute) : this(new BindingPair(attribute.Name, factory.ReturnType))
            {
                Dependencies = new List <IBindingProvider>();

                if (attribute.DependencyCount > 0)
                {
                    var parameters = factory.GetParameters();

                    for (int i = 0; i < attribute.DependencyCount; ++i)
                    {
                        var type = parameters[i].ParameterType;

                        object name = InnerBindingNames.Empty;

                        if (attribute.DependencieNames.Length > i)
                        {
                            name = attribute.DependencieNames[i];
                        }

                        var duo = new BindingPair(name, type);
                        Dependencies.Add(new ReflectionBindingProvider(duo));
                    }
                }
            }
 private ReflectionBindingProvider(BindingPair duo)
 {
     m_duo        = duo;
     Dependencies = new List <IBindingProvider>();
 }