Presenter = null in Page_PreInit ?

May 14, 2008 at 6:09 PM

I posted this earlier in issue tracker but no reply. Think that I will ask again here hoping to find an answer ..

In summary:
protected void Page_PreInit(object sender, EventArgs e)

will throws null error as _presenter variable is not initialised yet. This doesn't happen in May 2007 release version but not in the latest Feb 2008 version.

Is this an error or it shall be like that ?  Thanks.

May 14, 2008 at 7:13 PM
Call base.OnPreInit(e) before you do anything else.
Due to the fact that the ASP.NET pipeline controls page creation, and the page lifecycle varies depending on circumstances, OnPreInit was the only place we could reliably tie in dependency injection on Pages, UserControls, and MasterPages.  

Michael Puleio - patterns & practices
May 18, 2008 at 4:34 PM
I try it.. If I put it inside Page_PreInit(object sender, EventArgs e), it will go into infinite loop. 

I cannot put inside 
Page_Load(object sender, EventArgs e) either, as it will not be called until Page_PreInit().

fyi, I am trying to use it to dynamically change the masterpagefile of the current content page, i.e.:
this.MasterPageFile = "/Shared/Blank.master";

So, from your explanation that it has been used for the DI setting up purpose, I just have to leave the line as it is in the view class.

May 19, 2008 at 6:25 PM
Try with this:
protected void Page_PreInit(object sender, EventArgs e)

…and add this using:
using Microsoft.Practices.CompositeWeb;

It is not an error, in the Feb 2008 version, the dependencies injection is done at the OnPreInit event of the page, that is implemented in the overridden page (note that now your pages should derive from Microsoft.Practices.CompositeWeb.Web.UI.Page).

Jonathan Cisneros