I have a ApiController with a parameterized constructor. I read it is possible that the framework creates the controller using dependency injection.
So I does this (like explained here http://code.google.com/p/autofac/wiki/MvcIntegration):
Global.asax
builder.RegisterControllers(Assembly.GetExecutingAssembly());
//or this
builder.RegisterType<ObjectsController>().InstancePerHttpRequest();
The controller looks like this:
public class ObjectsController : ApiController
{
IMyObject m_myObject = null;
public ObjectsController(IMyObject obj)
{
m_myObject = obj;
}
}
Global.asax To resolve the dependency I used this:
builder.Register<IMyObject >((c, p) =>
{
//... create object ...
return obj;
}).InstancePerHttpRequest();
But I get this error:
"ObjectsController' does not have a default constructor.
I thought I can do this using DI