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> /// Determines which factories should be used /// for a particular service request. /// </summary> /// <param name="storage">The <see cref="IFactoryStorage"/> object that holds 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> /// <returns>A factory instance.</returns> public static IFactory GetFactory(this IFactoryStorage storage, string serviceName, Type serviceType, IEnumerable <Type> additionalParameterTypes) { var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes); return(storage.GetFactory(info)); }
/// <summary> /// Determines which factories should be used /// for a particular service request. /// </summary> /// <param name="storage">The <see cref="IFactoryStorage"/> object that holds 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="additionalParameters">The list of additional parameter values that this factory type will use to instantiate the service.</param> /// <returns>A factory instance.</returns> public static IFactory GetFactory(this IFactoryStorage storage, string serviceName, Type serviceType, IEnumerable <object> additionalParameters) { var additionalParameterTypes = from arg in additionalParameters let argType = arg != null?arg.GetType() : typeof(object) select argType; var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes); return(storage.GetFactory(info)); }