How is the Web API Controller's constructor called?

Viewed 27182

According to this article, a Controller should have a constructor that gets the interface to be implemented passed in, a la:

public class DuckbillsController : ApiController
{
    IDuckbillRepository _platypiRepository;

    public DuckbillsController(IDuckbillRepository platypiRepository)
    {
        if (platypiRepository == null)
        {
            throw new ArgumentNullException("platypiRepository is null");
        }
        _platypiRepository = platypiRepository;
    }
}

But how is this constructor called? A reckon via a client calling a Web API method contained within this class, but how does it get passed the Interface type? Or does that not have to happen (constructor is not explicitly called by anyone/from anywhere)?

UPDATE

The canonical examples show "private readonly" prepended to the Interface declaration, but that is not necessary for it to compile. Is there a compiling, I mean compelling, reason, for me to prepend "private readonly"?

3 Answers
Related