private ServiceDescriptor TryToDiscover(Type serviceType) { if (EnumerableStep.IsEnumerable(serviceType)) { return(null); } if (serviceType.IsGenericType) { var basicType = serviceType.GetGenericTypeDefinition(); var templatedParameterTypes = serviceType.GetGenericArguments(); var candidates = _services.Where(x => x.ServiceType == basicType && x.ImplementationType != null).Select(x => { return(new ServiceDescriptor(serviceType, x.ImplementationType.MakeGenericType(templatedParameterTypes), x.Lifetime)); }).ToArray(); _services.AddRange(candidates); if (candidates.Any()) { return(candidates.LastOrDefault()); } } if (serviceType.IsConcrete() && !serviceType.IsGenericTypeDefinition && ChooseConstructor(serviceType) != null) { return(new ServiceDescriptor(serviceType, serviceType, ServiceLifetime.Transient)); } return(null); }
private BuildStep findStep(Type type) { // INSTEAD, let's pull all variable sources // If not a ServiceVariable, use the KnownVariableBuildStep, otherwise use the // parent build step and do NOT visit its dependencies var variable = _method.TryFindVariable(type, VariableSource.NotServices); if (variable != null) { return(new KnownVariableBuildStep(variable)); } var @default = _graph.FindDefault(type); if (@default == null) { if (EnumerableStep.IsEnumerable(type)) { return(tryFillEnumerableOfAllKnown(type)); } return(null); } return(findStep(@default)); }