views:

53

answers:

1

I see from poking around in the 1.4.4 source that Autofac's ASP.NET integration (via Autofac.Integration.Web) peforms injection of properties on the Page as part of the HttpContext.PreRequestHandlerExecute event handling, but that the page's child controls don't get their properties injected until Page.PreLoad.

What this means, though is that the injected properties of child controls are unavailable for use in the OnInit event handler.

For example, this works fine:

HelloWorld.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HelloWorld.aspx.cs" Inherits="HelloWorld" %>
<html>
  <body>
    <asp:Label runat="server" id="lblMsg" OnInit="HandleInit"/>
  </body>
</html>

HelloWorld.aspx.cs:
...
protected void HandleInit()
{
    lblMsg.Text = _msgProvider.GetMessage();
}

public IMsgProvider _msgProvider { private get; set; } // <-- Injected

But changing the HelloWorld Page to a UserControl (.acsx) and putting the UserControl in another page doesn't work because _msgProvider isn't injected early enough.

Is there a way to make Autofac inject properties of child controls earlier? Or is this something that can be addressed in a future build? Thanks!

A: 

I came up with a small patch to Autofac for this issue. See the issue tracker at the Google Code project for details.

David Rubin