public virtual object Apply(Type targetType, Injector activeInjector, Dictionary <string, object> injectParameters) { object instance = provider.Apply(targetType, activeInjector, injectParameters); if (_postApply != null) { _postApply(this, instance); } return(instance); }
protected virtual object[] GatherParameterValues(Type targetType, Injector injector) { if (_methodBase == null) { return(new object[0]); } List <object> parameters = new List <object> (); ParameterInfo[] parameterInfos = _methodBase.GetParameters(); int length = parameterInfos.Length; for (int i = 0; i < length; i++) { Type parameterType = parameterInfos [i].ParameterType; MappingId mappingId; if (_keys != null && _keys.Length > i && _keys[i] != null) { mappingId = new MappingId(parameterType, _keys[i]); } else { mappingId = new MappingId(parameterType); } DependencyProvider provider = injector.GetProvider(mappingId); if (provider == null) { if (parameterInfos [i].IsOptional) { parameters.Add(parameterInfos [i].DefaultValue); continue; } if (_optional) { parameters.Add(null); continue; //TODO: Check optional parameters are in order (last) for this break to work, else use continue } throw(new InjectorMissingMappingException( "Injector is missing a mapping to handle constructor injection into target type '" + targetType.FullName + "'. \nTarget dependency: " + parameterType.FullName + ", method: " + _methodBase.Name + ", parameter: " + (i + 1) )); } parameters.Add(provider.Apply(targetType, injector, injectParameters)); } return(parameters.ToArray()); }
public override void ApplyInjection(object target, Type targetType, Injector injector) { DependencyProvider provider = injector.GetProvider(_mappingId); if (provider == null) { if (_optional) { return; } throw new InjectorMissingMappingException("Injector is missing a mapping to handle injection into property '" + _fieldInfo.Name + "' of object '" + target + "' with type '" + targetType.FullName + "'. Target dependency: '" + _mappingId + "'"); } _fieldInfo.SetValue(target, provider.Apply(targetType, injector, injectParameters)); }
public object GetInstance(Type type, object key = null, Type targetType = null) { MappingId mappingId = new MappingId(type, key); DependencyProvider provider = GetProvider(mappingId); if (provider == null) { provider = GetDefaultProvider(mappingId, true); } if (provider != null) { // ConstructorInjectionPoint ctor = _typeDescriptor.GetDescription(type).ctor; //TODO: Make this CTOR ConstructorInjectionPoint ctor = null; return(provider.Apply(targetType, this, ctor != null ? ctor.injectParameters : null)); } string fallbackMessage = _fallbackProvider != null ? "the fallbackProvider, '" + _fallbackProvider + "', was unable to fulfill this request." : "the injector has no fallbackProvider."; throw new InjectorMissingMappingException("No mapping found for request " + mappingId + " and " + fallbackMessage); }