예제 #1
0
        override protected void resolver(IBinding binding)
        {
            IInjectionBinding iBinding = binding as IInjectionBinding;

            object [] supply = iBinding.GetSupply();

            if (supply != null)
            {
                foreach (object a in supply)
                {
                    Type aType = a as Type;
                    if (suppliers.ContainsKey(aType) == false)
                    {
                        suppliers[aType] = new Dictionary <Type, IInjectionBinding>();
                    }
                    object[] keys = iBinding.key as object[];
                    foreach (object key in keys)
                    {
                        Type keyType = key as Type;
                        if (suppliers[aType].ContainsKey(keyType as Type) == false)
                        {
                            suppliers[aType][keyType] = iBinding;
                        }
                    }
                }
            }

            base.resolver(binding);
        }
예제 #2
0
        public void TestGetSupplier()
        {
            binder.Bind <ClassToBeInjected> ().To <ExtendsClassToBeInjected> ()
            .ToName("Supplier")
            .SupplyTo <InjectsClassToBeInjected> ();

            IInjectionBinding binding = binder.GetSupplier(typeof(ClassToBeInjected), typeof(InjectsClassToBeInjected));

            Assert.IsNotNull(binding);
            Assert.AreEqual(typeof(ClassToBeInjected), (binding.key as object[]) [0]);
            Assert.AreEqual(typeof(ExtendsClassToBeInjected), binding.value);
            Assert.AreEqual(typeof(InjectsClassToBeInjected), binding.GetSupply() [0]);
        }