fixed sprnet-1084

This commit is contained in:
eeichinger
2008-11-01 02:06:19 +00:00
parent f643c124d0
commit fc2afea7c7
3 changed files with 28 additions and 3 deletions

View File

@@ -602,7 +602,6 @@
<Compile Include="Objects\Factory\Xml\NamespaceParserSupport.cs" />
<Compile Include="Objects\Factory\Xml\ObjectDefinitionParserHelper.cs" />
<Compile Include="Objects\Factory\Xml\ParserContext.cs" />
<Compile Include="Objects\Factory\Xml\XmlObjectDefinitionStoreException.cs" />
<Compile Include="Objects\Factory\Xml\XmlReaderContext.cs" />
<Compile Include="Objects\FatalObjectException.cs" />
<Compile Include="Objects\ISharedStateAware.cs" />

View File

@@ -18,6 +18,7 @@
#region Imports
using System.Web.UI;
using Spring.Context;
#endregion
@@ -33,7 +34,10 @@ namespace Spring.Web.Support
public bool Intercept(IApplicationContext defaultApplicationContext, ControlAccessor ctlAccessor,
ControlCollectionAccessor ctlColAccessor)
{
ctlColAccessor.Owner = new SupportsWebDependencyInjectionOwnerProxy(defaultApplicationContext, ctlAccessor.GetTarget() );
Control target = ctlAccessor.GetTarget();
ctlColAccessor.Owner = target is INamingContainer
? new NamingContainerSupportsWebDependencyInjectionOwnerProxy(defaultApplicationContext, target)
: new SupportsWebDependencyInjectionOwnerProxy(defaultApplicationContext, target);
return true;
}
}

View File

@@ -18,9 +18,11 @@
#region Imports
using System.Reflection;
using System.Web.UI;
using Spring.Context;
using Spring.Context.Support;
using Spring.Reflection.Dynamic;
using Spring.Web.Support;
#endregion
@@ -28,7 +30,7 @@ using Spring.Web.Support;
namespace Spring.Web.Support
{
/// <summary>
/// Wraps a Control to make it DI aware
/// Wraps a ControlCollection.Owner control to make it DI aware
/// </summary>
/// <author>Erich Eichinger</author>
internal class SupportsWebDependencyInjectionOwnerProxy : Control, ISupportsWebDependencyInjection
@@ -79,4 +81,24 @@ namespace Spring.Web.Support
_targetControl.RemovedControl(control);
}
}
/// <summary>
/// Wraps a ControlCollection.Owner control implementing INamingContainer to make it DI aware
/// </summary>
/// <author>Erich Eichinger</author>
internal class NamingContainerSupportsWebDependencyInjectionOwnerProxy : SupportsWebDependencyInjectionOwnerProxy
, INamingContainer
{
#if NET_2_0
private static readonly SafeField refOccasionalFields = new SafeField(typeof(Control).GetField("_occasionalFields", BindingFlags.Instance|BindingFlags.NonPublic));
#endif
public NamingContainerSupportsWebDependencyInjectionOwnerProxy(IApplicationContext defaultApplicationContext, Control targetControl) : base(defaultApplicationContext, targetControl)
{
#if NET_2_0
object targetOccasionalFields = refOccasionalFields.GetValue(targetControl);
refOccasionalFields.SetValue(this, targetOccasionalFields);
#endif
}
}
}