public void ShouldDistinguishBetweenTwoServicesOfTheSameTypeButDifferentParameters() { var firstFactory = new Mock <IFactory>(); var secondFactory = new Mock <IFactory>(); var serviceType = typeof(int); IEnumerable <Type> firstParameters = new Type[] { typeof(int), typeof(int) }; IEnumerable <Type> secondParameters = new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }; _storage.AddFactory("", serviceType, firstParameters, firstFactory.Object); _storage.AddFactory("", serviceType, secondParameters, secondFactory.Object); Assert.IsTrue(_storage.ContainsFactory("", serviceType, firstParameters)); Assert.IsTrue(_storage.ContainsFactory("", serviceType, secondParameters)); // Make sure that the factory returns the correct container var firstResult = _storage.GetFactory("", serviceType, firstParameters); Assert.AreSame(firstFactory.Object, firstResult); var secondResult = _storage.GetFactory("", serviceType, secondParameters); Assert.AreSame(secondFactory.Object, secondResult); }
/// <summary> /// Adds a factory to the current <see cref="IFactoryStorage"/> instance. /// </summary> /// <param name="storage">The <see cref="IFactoryStorage"/> object that will store the target factory.</param> /// <param name="serviceName">The name that will be associated with the target factory.</param> /// <param name="serviceType">The service type that the factory will be able to create.</param> /// <param name="additionalParameterTypes">The list of additional parameters that this factory type will support.</param> /// <param name="factory">The <see cref="IFactory"/> instance that will create the object instance.</param> public static void AddFactory(this IFactoryStorage storage, string serviceName, Type serviceType, IEnumerable <Type> additionalParameterTypes, IFactory factory) { var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes); storage.AddFactory(info, factory); }