Microsoft unity buildup a controller in a web api 2.0 application

Jan 25, 2015 at 1:50 PM
I have an ASP.NET application and I am using web API 2.0. To use Web Api I have created a controller... Ok, there is no problem to call the controller, but in the controller I have a Property that should be resolved with unity:
public IFacade.IPublicAreaFacade PublicFacade { get; set; }
The problem is that the property PublicFacade remains null...

Here the code I am using to resolve the dependency:
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    var handler =
        HttpContext.Current.Handler as System.Web.Http.WebHost.HttpControllerHandler; //as System.Web.UI.Page;

    if (handler != null)
        this._container = Application.GetContainer();

        if (this._container != null)
            this._container.BuildUp(handler.GetType(), handler);
This code work perfectly if I have the dependency in a Page (changing the cast that is commented), but it does not work if I have it in the controller.

How can I solve?

Thanx you