예제 #1
0
        public void TestGetBindingFlat()
        {
            binder.Bind <InjectableSuperClass> ().To <InjectableSuperClass> ();
            IInjectionBinding binding = binder.GetBinding <InjectableSuperClass> () as IInjectionBinding;

            Assert.IsNotNull(binding);
        }
예제 #2
0
        /*
         * Injections.
         */

        private void Inject(object instance, IMVCSItemReflectionInfo info)
        {
            foreach (var injection in info.Injections)
            {
                var binding = _binder.GetBinding(injection.PropertyInfo.PropertyType);
                if (binding == null)
                {
                    throw new InjectionException(InjectionExceptionType.BindingIsMissing, $"Binding: {injection}", $"Injection target: {instance.GetType().FullName}");
                }

                var value = GetInstance(binding, instance, injection);
                if (!injection.PropertyInfo.PropertyType.IsInstanceOfType(value))
                {
                    throw new InjectionException(InjectionExceptionType.InjectionTypeMismatch, injection, value.GetType().Name);
                }

                injection.PropertyInfo.SetValue(instance, value, null);
            }
        }