Exemplo n.º 1
0
        public override void GetBindings(IDictionary <string, Binding> bindings)
        {
            for (var t = ModuleType; t != typeof(object); t = t.BaseType)
            {
                // t will always be typeof(object) before it is null.
                // ReSharper disable PossibleNullReferenceException
                var methods = t.GetMethods(DeclaredMethods);
                // ReSharper restore PossibleNullReferenceException
                for (var i = 0; i < methods.Length; ++i)
                {
                    var m    = methods[i];
                    var attr = m.GetSingleAttribute <ProvidesAttribute>();
                    if (attr == null)
                    {
                        continue;
                    }

                    var key = Key.Get(m.ReturnType, m.GetQualifierName());
                    switch (attr.ProvidesType)
                    {
                    case ProvidesType.Default:
                        AddNewBinding(bindings, key, m);
                        break;

                    case ProvidesType.Set:

                        ReflectionSetBinding.Add(bindings, Key.GetSetKey(key), new ProviderMethodBinding(m, key, Module, IsLibrary));
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void Add(IDictionary <string, Binding> bindings, string key, Binding binding)
        {
            Binding        previous;
            SetBindingBase setBinding;

            if (bindings.TryGetValue(key, out previous))
            {
                setBinding = previous as SetBindingBase;

                if (setBinding == null)
                {
                    throw new ArgumentException("Duplicates:\n" + previous + "\n" + binding);
                }

                setBinding.IsLibrary = setBinding.IsLibrary && binding.IsLibrary;
            }
            else
            {
                setBinding = new ReflectionSetBinding(key, binding.RequiredBy)
                {
                    IsLibrary = binding.IsLibrary
                };

                bindings.Add(key, setBinding);
            }

            setBinding.Contributors.Add(Resolver.Scope(binding));
        }