Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/UI/Controls
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv25332
Modified Files:
Panel.cs
Log Message:
SPRNET-794 improved Panel for use without Spring's PageHandlerFactory
Index: Panel.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/UI/Controls/Panel.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Panel.cs 3 Feb 2008 21:38:27 -0000 1.2
--- Panel.cs 9 Mar 2008 15:20:37 -0000 1.3
***************
*** 22,26 ****
--- 22,29 ----
using System;
+ using System.Collections;
using System.ComponentModel;
+ using System.Diagnostics;
+ using System.Reflection;
using System.Security.Permissions;
using System.Web;
***************
*** 57,60 ****
--- 60,91 ----
public class Panel : System.Web.UI.WebControls.Panel, ISupportsWebDependencyInjection
{
+ // this helper class intercepts the first call to the child controls
+ // collection from within InitRecursive().
+ // InitRecursive() is called right after the control has been added to it's parent's children.
+ private class InitRecursiveInterceptingControlsCollection : ControlCollection
+ {
+ private bool _passedInitRecursiveCheck = false;
+
+ public InitRecursiveInterceptingControlsCollection(Control owner) : base(owner)
+ {
+ }
+
+ public override Control this[int index]
+ {
+ get
+ {
+ // the following check relies on the fact, that ControlCollection is set readonly
+ // right before InitRecursive() is called on each child control
+ if (!_passedInitRecursiveCheck
+ && this.IsReadOnly)
+ {
+ _passedInitRecursiveCheck = true;
+ ((Panel)this.Owner).OnPreInitRecursive(EventArgs.Empty);
+ }
+ return base[index];
+ }
+ }
+ }
+
private bool _suppressDependencyInjection;
private bool _renderContainerTag;
***************
*** 95,98 ****
--- 126,145 ----
}
+ /// <summary>
+ /// This method is invoked right before InitRecursive() is called for this Panel and
+ /// ensures, that dependencies get injected on child controls before their Init event is raised.
+ /// </summary>
+ protected virtual void OnPreInitRecursive(EventArgs e)
+ {
+ if (!_suppressDependencyInjection
+ && _defaultApplicationContext == null)
+ {
+ // obtain appContext of the closed parent template (.ascx/.aspx) control
+ IApplicationContext appCtx = WebApplicationContext.GetContext(this.TemplateSourceDirectory.TrimEnd('/') + "/");
+ // NOTE: _defaultApplicationContext will be set during DI!
+ WebDependencyInjectionUtils.InjectDependenciesRecursive(appCtx, this);
+ }
+ }
+
#region Dependency Injection Support
***************
*** 113,117 ****
protected override void AddedControl(Control control, int index)
{
! if (!_suppressDependencyInjection)
{
WebDependencyInjectionUtils.InjectDependenciesRecursive(_defaultApplicationContext, control);
--- 160,165 ----
protected override void AddedControl(Control control, int index)
{
! if (!_suppressDependencyInjection
! && _defaultApplicationContext != null)
{
WebDependencyInjectionUtils.InjectDependenciesRecursive(_defaultApplicationContext, control);
***************
*** 131,137 ****
{
_defaultApplicationContext = WebApplicationContext.GetRootContext();
}
-
- return base.CreateControlCollection();
}
--- 179,188 ----
{
_defaultApplicationContext = WebApplicationContext.GetRootContext();
+ return base.CreateControlCollection();
+ }
+ else
+ {
+ return new InitRecursiveInterceptingControlsCollection(this);
}
}
|