private object Resolve(Type interfaceType, string id) { if (!IsInterfaceValid(ref interfaceType, out var args)) { throw new DependencyException($"No dependency for the {interfaceType.Name}"); } List <Dependency> dependencies = DependenciesConfiguration.GetDependencies(interfaceType); if (dependenciesStack.Contains(interfaceType)) { throw new DependencyException("Beans have cyclic dependency"); } dependenciesStack.Push(interfaceType); Dependency foundDependency = dependencies.FirstOrDefault(dependency => dependency.Id.Equals(id)); if (foundDependency == null) { throw new DependencyException($"Bean {id} is not registered"); } object bean = ResolveDependency(args == null ? foundDependency : new Dependency(foundDependency.ImplType.MakeGenericType(args), foundDependency.Scope, foundDependency.Id)); dependenciesStack.Pop(); return(bean); }
public IEnumerable<T> ResolveAll<T>() where T : class { IList collection = null; Type type = typeof(T); var dependencies = configuration.GetDependencies(type); if (dependencies != null) { collection = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(type)); foreach (var dependency in dependencies) { collection.Add(GetInstance(dependency)); } } return (IEnumerable<T>)collection; }