refactoring as suggested in PR #57

pull/57/head
JCH2k 4 years ago
parent 0b5f24ea04
commit 75233628d0
  1. 6
      LightweightIocContainer/Validation/IocValidator.cs
  2. 2
      Test.LightweightIocContainer/IocValidatorTest.cs

@ -47,12 +47,13 @@ namespace LightweightIocContainer.Validation
foreach (IRegistration registration in _iocContainer.Registrations) foreach (IRegistration registration in _iocContainer.Registrations)
{ {
var definedParameters = _parameters.Where(p => p.type == registration.InterfaceType);
if (registration is IWithFactoryInternal { Factory: { } } withFactoryRegistration) if (registration is IWithFactoryInternal { Factory: { } } withFactoryRegistration)
{ {
(from createMethod in withFactoryRegistration.Factory.CreateMethods (from createMethod in withFactoryRegistration.Factory.CreateMethods
select createMethod.GetParameters().Select(p => p.ParameterType) select createMethod.GetParameters().Select(p => p.ParameterType)
into parameterTypes into parameterTypes
let definedParameters = _parameters.Where(p => p.type == registration.InterfaceType)
select (from parameterType in parameterTypes select (from parameterType in parameterTypes
let definedParameter = definedParameters let definedParameter = definedParameters
.FirstOrDefault(p => parameterType.IsInstanceOfType(p.parameter)) .FirstOrDefault(p => parameterType.IsInstanceOfType(p.parameter))
@ -62,8 +63,7 @@ namespace LightweightIocContainer.Validation
} }
else else
{ {
var parameters = _parameters.Where(p => p.type == registration.InterfaceType); var arguments = definedParameters.Select(p => p.parameter).ToArray();
var arguments = parameters.Select(p => p.parameter).ToArray();
TryResolve(registration.InterfaceType, arguments, validationExceptions); TryResolve(registration.InterfaceType, arguments, validationExceptions);
} }
} }

@ -72,7 +72,7 @@ namespace Test.LightweightIocContainer
} }
[Test] [Test]
public void TestValidate_WithFactory() public void TestValidateWithFactory()
{ {
IocContainer iocContainer = new(); IocContainer iocContainer = new();
iocContainer.Install(new TestInstallerWithFactory()); iocContainer.Install(new TestInstallerWithFactory());

Loading…
Cancel
Save