diff --git a/LightweightIocContainer/LightweightIocContainer.csproj b/LightweightIocContainer/LightweightIocContainer.csproj index 95e8fb3..daf6f0c 100644 --- a/LightweightIocContainer/LightweightIocContainer.csproj +++ b/LightweightIocContainer/LightweightIocContainer.csproj @@ -27,6 +27,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/LightweightIocContainer/Validation/IocValidator.cs b/LightweightIocContainer/Validation/IocValidator.cs index 6a3026c..275c878 100644 --- a/LightweightIocContainer/Validation/IocValidator.cs +++ b/LightweightIocContainer/Validation/IocValidator.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using LightweightIocContainer.Interfaces.Registrations; using LightweightIocContainer.Interfaces.Registrations.Fluent; +using Moq; namespace LightweightIocContainer.Validation { @@ -55,7 +56,7 @@ namespace LightweightIocContainer.Validation select (from parameterType in parameterTypes let definedParameter = definedParameters .FirstOrDefault(p => parameterType.IsInstanceOfType(p.parameter)) - select definedParameter == default ? parameterType.GetDefault() : definedParameter.parameter).ToArray()) + select definedParameter == default ? GetMockOrDefault(parameterType) : definedParameter.parameter).ToArray()) .ToList() .ForEach(p => TryResolve(registration.InterfaceType, p, validationExceptions)); } @@ -78,5 +79,9 @@ namespace LightweightIocContainer.Validation validationExceptions.Add(exception); } } + + private T GetMock() where T : class => new Mock().Object; + private object? GetMockOrDefault(Type type) => + type.IsValueType ? Activator.CreateInstance(type) : GenericMethodCaller.CallPrivate(this, nameof(GetMock), type); } } \ No newline at end of file