Closed GoogleCodeExporter closed 8 years ago
G'day - thanks for the report.
In the most recent Autofac MVC integration (2.4.x) the parameter injection
behaviour is switched off by default, which will fix this problem. We disabled
the feature because of this kind of scenario - Autofac can always resolve
arrays of items (an empty array just means no components with that service have
been registered) but of course in this case the outcome is unpredictable.
If you are using parameter injection elsewhere in your MVC app I'd suggest
subclassing ExtensibleActionInvoker to alter the behavior.
Hope this helps,
Nick
Original comment by nicholas...@gmail.com
on 8 May 2011 at 6:10
Ah cool. I'd already done that as a workaround. What I did was:
protected override object GetParameterValue(ControllerContext
controllerContext, ParameterDescriptor parameterDescriptor)
{
var result = base.GetParameterValue(controllerContext, parameterDescriptor);
if (result == null && this._context.IsRegistered(parameterDescriptor.ParameterType))
result = this._context.Resolve(parameterDescriptor.ParameterType);
return result;
}
So, it only tries to resolve the parameter if it can't be found by the base
invoker. In other words, it's only injected if not passed in. Wouldn't this be
an acceptable default behaviour?
Original comment by sean.hed...@gmail.com
on 8 May 2011 at 7:10
Original issue reported on code.google.com by
sean.hed...@gmail.com
on 6 May 2011 at 6:34