diff --git a/LightweightIocContainer.Validation/IocValidator.cs b/LightweightIocContainer.Validation/IocValidator.cs index 12065eb..c4b7bb2 100644 --- a/LightweightIocContainer.Validation/IocValidator.cs +++ b/LightweightIocContainer.Validation/IocValidator.cs @@ -60,6 +60,21 @@ public class IocValidator(IocContainer iocContainer) private void TryResolve(Type type, object?[]? arguments, List validationExceptions, bool isFactoryResolve = false) { + if (type.ContainsGenericParameters) + { + List genericParameters = []; + + Type[] genericArguments = type.GetGenericArguments(); + foreach (Type genericArgument in genericArguments.Where(g => g.IsGenericParameter)) + { + Type[] genericParameterConstraints = genericArgument.GetGenericParameterConstraints(); + object mock = Substitute.For(genericParameterConstraints, []); + genericParameters.Add(mock.GetType()); + } + + type = type.MakeGenericType(genericParameters.ToArray()); + } + (bool success, object _, Exception? exception) = iocContainer.TryResolveNonGeneric(type, arguments, null, isFactoryResolve); if (success) return;