public T GetInstance <T>() { _IsBindingCompleted = true; Type bindingType = typeof(T); object value = null; InjectionBinding binding = null; if (_Bindings.TryGetValue(bindingType, out binding) == true) { value = GetInstanceAndInit(binding.InstanceProvider); } else { // Handler error InjectionError error = CreateError(InjectionErrorType.CanNotFindBindingForType, bindingType, null, 1); if (_ShouldThrowException) { throw new InjectionException(error.Error, error.Message); } } return((T)value); }
public bool InjectIntoProperty(PropertyInfo propertyInfo, object container) { InjectionBinding binding = null; if (_Bindings.TryGetValue(propertyInfo.PropertyType, out binding) == true) { object value = GetInstanceAndInit(binding.InstanceProvider); propertyInfo.SetValue(container, value, null); return(true); } return(false); }
public bool InjectIntoField(FieldInfo fieldInfo, object container) { InjectionBinding binding = null; if (_Bindings.TryGetValue(fieldInfo.FieldType, out binding) == true) { object value = GetInstanceAndInit(binding.InstanceProvider); fieldInfo.SetValue(container, value); return(true); } return(false); }
public IInstanceProviderSetter AddBinding <T>() { Type bindingType = typeof(T); InjectionBinding binding = null; if (!_IsBindingCompleted) { // Check is there is an existing binding with given type if (_Bindings.TryGetValue(bindingType, out binding)) { // Handler error InjectionError error = CreateError(InjectionErrorType.AlreadyAddedBindingForType, bindingType, null, 1); if (_ShouldThrowException) { throw new InjectionException(error.Error, error.Message); } } else { // Add binding binding = new InjectionBinding(bindingType, this); _Bindings.Add(bindingType, binding); } } else { // Handler error InjectionError error = CreateError(InjectionErrorType.BindingAfterInjection, bindingType, null, 1); if (_ShouldThrowException) { throw new InjectionException(error.Error, error.Message); } } return(binding); }