protected IEnumerable <object> ResolveGeneric(Type dependency, string name) { List <object> result = new List <object>(); IEnumerable <ImplementationContainer> implementationContainers = configuration.GetImplementations(dependency) .Where((impl) => !recursionTypesExcluder[Thread.CurrentThread.ManagedThreadId].Contains(impl.ImplementationType)); if (name != null) { implementationContainers = implementationContainers.Where((container) => container.Name == name); } object instance; foreach (ImplementationContainer implementationContainer in implementationContainers) { instance = CreateByConstructor(implementationContainer.ImplementationType.GetGenericTypeDefinition() .MakeGenericType(dependency.GenericTypeArguments)); if (instance != null) { result.Add(instance); } } return(result); }
public void NonGenericTypeRegisterTest() { config.Register <IMyInterface, MyImplementation1>(); config.Register <IMyInterface, MyImplementation2>(); var registeredImplementations = config.GetImplementations(typeof(IMyInterface)).ToList(); Assert.AreEqual(2, registeredImplementations.Count); List <Type> expectedRegisteredTypes = new List <Type> { typeof(MyImplementation1), typeof(MyImplementation2) }; CollectionAssert.AreEquivalent(expectedRegisteredTypes, registeredImplementations.Select((implementation) => implementation.ImplementationType).ToList()); }