sprnet-840: fixed broken DI support w/ Server.Transfer()/Server.Execute()

This commit is contained in:
eeichinger
2008-10-06 13:09:03 +00:00
parent b25755d9df
commit e4f60e9c68
4 changed files with 51 additions and 31 deletions

View File

@@ -10,7 +10,7 @@
<h2><a href="../../Default.aspx">Welcome to Spring.NET Web Framework Quick Start Guide</a></h2>
<h2><a href="../Default.aspx">Dependency Injection</a></h2>
<div>
<h2>Hello World example</h2>
<h2><a href="splashpage.aspx">Hello World example</a></h2>
<form id="form1" runat="server">
<p>
This very simple web form demonstrates dependency injection on pages and controls.

View File

@@ -0,0 +1,3 @@
<%@ Page Language="C#" EnableViewState="false" AutoEventWireup="false" Inherits="System.Web.UI.Page" %>
<p>This page demonstrates DI when being used in combination with Server.Execute()/Transfer()
<%Server.Execute("Default.aspx");%>

View File

@@ -175,10 +175,8 @@ namespace Spring.Context.Support
///<param name="applicationContext"></param>
///<param name="name"></param>
///<param name="isContainerManaged"></param>
public IHttpHandler ConfigureHandler( IHttpHandler handler, IConfigurableApplicationContext applicationContext, string name, bool isContainerManaged)
public static IHttpHandler ConfigureHandler( IHttpHandler handler, IConfigurableApplicationContext applicationContext, string name, bool isContainerManaged)
{
ApplyDependencyInjectionInfrastructure(handler, applicationContext);
if (isContainerManaged)
{
handler = (IHttpHandler)applicationContext.ObjectFactory.ConfigureObject( handler, name );
@@ -193,26 +191,6 @@ namespace Spring.Context.Support
return handler;
}
/// <summary>
/// Apply dependency injection stuff on the handler.
/// </summary>
/// <param name="handler">the handler to be intercepted</param>
/// <param name="applicationContext">the context responsible for configuring this handler</param>
private static void ApplyDependencyInjectionInfrastructure(IHttpHandler handler, IApplicationContext applicationContext)
{
if (handler is Control)
{
ControlInterceptor.EnsureControlIntercepted(applicationContext, (Control)handler);
}
else
{
if (handler is ISupportsWebDependencyInjection)
{
((ISupportsWebDependencyInjection)handler).DefaultApplicationContext = applicationContext;
}
}
}
/// <summary>
/// Disposes this instance
/// </summary>

View File

@@ -22,14 +22,9 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using Common.Logging;
using Spring.Collections;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects;
@@ -107,16 +102,60 @@ namespace Spring.Web.Support
if (namedPageDefinition != null)
{
handler = (IHttpHandler)appContext.CreateObject(namedPageDefinition.Name, typeof(IHttpHandler), null);
// is this a nested call (HttpServerUtility.Transfer() or HttpServerUtility.Execute())?
if (context.Handler != null)
{
// all deps can/must be resolved now
handler = (IHttpHandler)appContext.GetObject(namedPageDefinition.Name, typeof(IHttpHandler), null);
}
else
{
// execution pipeline "entry-point" - create page instance only
// and defer configuration to PreRequestHandlerExecute step
handler = (IHttpHandler)appContext.CreateObject(namedPageDefinition.Name, typeof(IHttpHandler), null);
}
WebSupportModule.SetCurrentHandlerConfiguration(appContext, namedPageDefinition.Name, true);
}
else
{
handler = WebObjectUtils.CreatePageInstance(url);
WebSupportModule.SetCurrentHandlerConfiguration(appContext, url, false);
// is this a nested call (HttpServerUtility.Transfer() or HttpServerUtility.Execute())?
if (context.Handler != null)
{
// apply ObjectPostProcessors now
handler = WebSupportModule.ConfigureHandler(handler, appContext, url, false);
}
else
{
// execution pipeline "entry-point" - create page instance only
// and defer configuration to PreRequestHandlerExecute step
WebSupportModule.SetCurrentHandlerConfiguration(appContext, url, false);
}
}
ApplyDependencyInjectionInfrastructure(handler, appContext);
return handler;
}
/// <summary>
/// Apply dependency injection stuff on the handler.
/// </summary>
/// <param name="handler">the handler to be intercepted</param>
/// <param name="applicationContext">the context responsible for configuring this handler</param>
private static void ApplyDependencyInjectionInfrastructure(IHttpHandler handler, IApplicationContext applicationContext)
{
if (handler is Control)
{
ControlInterceptor.EnsureControlIntercepted(applicationContext, (Control)handler);
}
else
{
if (handler is ISupportsWebDependencyInjection)
{
((ISupportsWebDependencyInjection)handler).DefaultApplicationContext = applicationContext;
}
}
}
}
}