diff --git a/LightweightIocContainer/Validation/IocValidator.cs b/LightweightIocContainer/Validation/IocValidator.cs index 6381704..4c61068 100644 --- a/LightweightIocContainer/Validation/IocValidator.cs +++ b/LightweightIocContainer/Validation/IocValidator.cs @@ -47,12 +47,13 @@ namespace LightweightIocContainer.Validation foreach (IRegistration registration in _iocContainer.Registrations) { + var definedParameters = _parameters.Where(p => p.type == registration.InterfaceType); + if (registration is IWithFactoryInternal { Factory: { } } withFactoryRegistration) { (from createMethod in withFactoryRegistration.Factory.CreateMethods select createMethod.GetParameters().Select(p => p.ParameterType) into parameterTypes - let definedParameters = _parameters.Where(p => p.type == registration.InterfaceType) select (from parameterType in parameterTypes let definedParameter = definedParameters .FirstOrDefault(p => parameterType.IsInstanceOfType(p.parameter)) @@ -62,8 +63,7 @@ namespace LightweightIocContainer.Validation } else { - var parameters = _parameters.Where(p => p.type == registration.InterfaceType); - var arguments = parameters.Select(p => p.parameter).ToArray(); + var arguments = definedParameters.Select(p => p.parameter).ToArray(); TryResolve(registration.InterfaceType, arguments, validationExceptions); } } diff --git a/Test.LightweightIocContainer/IocValidatorTest.cs b/Test.LightweightIocContainer/IocValidatorTest.cs index f423d3d..181308e 100644 --- a/Test.LightweightIocContainer/IocValidatorTest.cs +++ b/Test.LightweightIocContainer/IocValidatorTest.cs @@ -72,7 +72,7 @@ namespace Test.LightweightIocContainer } [Test] - public void TestValidate_WithFactory() + public void TestValidateWithFactory() { IocContainer iocContainer = new(); iocContainer.Install(new TestInstallerWithFactory());