public Object ProvideInjection(SPI.Instance.CompositeInstance instance, AbstractInjectableModel model, Type targetType) { var scope = model.InjectionScope; // First check if we are trying to reference ourselves //var gDef = TypeUtils.TypeUtil.GenericDefinitionIfGenericType( targetType ); Object result = null; var provider = instance.StructureOwner.StructureServices; var actualServiceType = GetActualServiceType(targetType); var refs = provider.FindServices(actualServiceType); foreach (var tuple in GetQualifierTypes(model)) { var qInstance = (ServiceQualifier)tuple.Item2.QualifierType.LoadConstructorOrThrow(0).Invoke(null); refs = refs.Where(sRef => qInstance.Qualifies(sRef, tuple.Item1)); } if (Object.Equals(actualServiceType, targetType)) { result = refs.Select(sRef => sRef.GetServiceWithType(actualServiceType)).FirstOrDefault(); } else { if (targetType.IsGenericType()) { var gArgs = targetType.GetGenericArguments(); if (Object.Equals(typeof(IEnumerable <>), targetType.GetGenericTypeDefinition())) { var enumerableType = gArgs[0]; if (enumerableType.IsGenericType() && Object.Equals(typeof(ServiceReferenceInfo <>), enumerableType.GetGenericTypeDefinition()) ) { result = GetTypedEnumerable(refs.Select(sRef => MakeRefToInfo(sRef, enumerableType.GetGenericArguments()[0])), enumerableType); } else { result = GetTypedEnumerable(refs.Select(sRef => sRef.GetServiceWithType(actualServiceType)), enumerableType); } } else { result = MakeRefToInfo(refs.FirstOrDefault(), gArgs[0]); } } } return(result); }
public Object ProvideInjection(SPI.Instance.CompositeInstance instance, AbstractInjectableModel model, Type targetType) { // Code generation will use Lazy<> by itself if needed, don't do check here. Object result; InjectionFunctionality func; var scope = model.InjectionScope; if (scope != null && this._functionalities.TryGetValue(scope.GetType(), out func)) { result = func.ProvideInjection(instance, model, targetType); } else { result = null; } return(result); }