diff --git a/LightweightIocContainer/InjectorContainer.cs b/LightweightIocContainer/InjectorContainer.cs
index 33b18a7..dd31495 100644
--- a/LightweightIocContainer/InjectorContainer.cs
+++ b/LightweightIocContainer/InjectorContainer.cs
@@ -72,29 +72,15 @@ namespace LightweightIocContainer
/// The constructor arguments
/// An instance of the given type
/// Could not find function
- public object Resolve(object type, object arguments) //somehow the order of the arguments is different in the application compared to the unit test
+ public object Resolve(Type type, object[] arguments) //somehow the order of the arguments is different in the application compared to the unit test
{
- Type realType;
- object[] realArguments;
-
- if (type == null || type.GetType().IsArray)
- {
- realType = (Type) arguments;
- realArguments = (object[]) type;
- }
- else
- {
- realType = (Type) type;
- realArguments = (object[]) arguments;
- }
-
var resolveMethod = typeof(InjectorContainer).GetMethod(nameof(ResolveInternal), BindingFlags.NonPublic | BindingFlags.Instance);
- var genericResolveMethod = resolveMethod?.MakeGenericMethod(realType);
+ var genericResolveMethod = resolveMethod?.MakeGenericMethod(type);
if (genericResolveMethod == null)
throw new InternalResolveException($"Could not find function {nameof(ResolveInternal)}");
- return genericResolveMethod.Invoke(this, new object[] {realArguments});
+ return genericResolveMethod.Invoke(this, new object[] {arguments});
}
///
diff --git a/LightweightIocContainer/Interfaces/IInjectorContainer.cs b/LightweightIocContainer/Interfaces/IInjectorContainer.cs
index 888dd72..2251175 100644
--- a/LightweightIocContainer/Interfaces/IInjectorContainer.cs
+++ b/LightweightIocContainer/Interfaces/IInjectorContainer.cs
@@ -46,6 +46,6 @@ namespace LightweightIocContainer.Interfaces
/// The given type
/// The constructor arguments
/// An instance of the given type
- object Resolve(object type, object arguments);
+ object Resolve(Type type, object[] arguments);
}
}
\ No newline at end of file
diff --git a/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs b/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs
index 127f321..293996d 100644
--- a/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs
+++ b/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs
@@ -100,6 +100,9 @@ namespace LightweightIocContainer.Registrations
generator.Emit(OpCodes.Ldfld, containerFieldBuilder);
generator.Emit(OpCodes.Ldtoken, createMethod.ReturnType);
+ MethodInfo getTypeFromHandle = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle));
+ generator.EmitCall(OpCodes.Call, getTypeFromHandle, null);
+
if (args.Any())
{
generator.Emit(OpCodes.Ldc_I4_S, args.Length);
@@ -119,7 +122,8 @@ namespace LightweightIocContainer.Registrations
generator.EmitCall(OpCodes.Call, emptyArray, null);
}
- generator.EmitCall(OpCodes.Callvirt, typeof(IInjectorContainer).GetMethod(nameof(IInjectorContainer.Resolve), new[] { typeof(object), typeof(object)}), null);
+ generator.EmitCall(OpCodes.Callvirt, typeof(IInjectorContainer).GetMethod(nameof(IInjectorContainer.Resolve), new[] { typeof(Type), typeof(object[])}), null);
+ generator.Emit(OpCodes.Castclass, createMethod.ReturnType);
generator.Emit(OpCodes.Ret);
}