Thanks Erich. That looks very handy for pages where I want DI to work in general, but have areas of heavily nested controls.
I'm still trying to generate a base class that turns off DI for anyone implementing it just to make it easy to have it off by default without relying on page naming conventions (almost our entire app implements a Page derived base class so this would be a good point to turn DI off by default) and haven't been successful. My properties are still injected. Here's what I've created:
Code:
public class SpringNoDIPage : Page, ISupportsWebDependencyInjection
{
public SpringNoDIPage()
{
}
#region ISupportsWebDependencyInjection Members
private IApplicationContext _defaultApplicationContext;
public IApplicationContext DefaultApplicationContext
{
get { return _defaultApplicationContext; }
set { _defaultApplicationContext = value; }
}
#endregion
protected override void AddedControl(Control control, int index)
{
//Note that this is WebDependencyInjectionUtils and not WebUtils. The docs are out of date. //WebDependencyInjectionUtils.InjectDependenciesRecursive(_defaultApplicationContext, control);
base.AddedControl(control, index);
}
}
Code:
public partial class Test_Spring_SpringNoDI : SpringNoDIPage
{
private string _TestMessage;
public string TestMessage
{
get { return _TestMessage; }
set { _TestMessage = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(String.Format("TestMessage Local Property: {0}<br>", TestMessage));
}
}
Code:
<object type="Test/Spring/SpringNoDI.aspx">
<property name="Title" value="Spring No DI Title"></property>
<property name="TestMessage" value="Hello From Spring No DI"></property>
</object>