From e4f60e9c688cd891f3148ee8d837817ed265eb4c Mon Sep 17 00:00:00 2001 From: eeichinger Date: Mon, 6 Oct 2008 13:09:03 +0000 Subject: [PATCH] sprnet-840: fixed broken DI support w/ Server.Transfer()/Server.Execute() --- .../DI/HelloWorld/Default.aspx | 2 +- .../DI/HelloWorld/Splashpage.aspx | 3 ++ .../Context/Support/WebSupportModule.cs | 24 +-------- .../Web/Support/PageHandlerFactory.cs | 53 ++++++++++++++++--- 4 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Splashpage.aspx diff --git a/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Default.aspx b/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Default.aspx index 0513813c..078082e1 100644 --- a/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Default.aspx +++ b/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Default.aspx @@ -10,7 +10,7 @@

Welcome to Spring.NET Web Framework Quick Start Guide

Dependency Injection

-

Hello World example

+

Hello World example

This very simple web form demonstrates dependency injection on pages and controls. diff --git a/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Splashpage.aspx b/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Splashpage.aspx new file mode 100644 index 00000000..669b6e06 --- /dev/null +++ b/examples/Spring/Spring.WebQuickStart/src/Spring.WebQuickStart.2005/DI/HelloWorld/Splashpage.aspx @@ -0,0 +1,3 @@ +<%@ Page Language="C#" EnableViewState="false" AutoEventWireup="false" Inherits="System.Web.UI.Page" %> +

This page demonstrates DI when being used in combination with Server.Execute()/Transfer() +<%Server.Execute("Default.aspx");%> \ No newline at end of file diff --git a/src/Spring/Spring.Web/Context/Support/WebSupportModule.cs b/src/Spring/Spring.Web/Context/Support/WebSupportModule.cs index 1a1a515c..f6fac471 100644 --- a/src/Spring/Spring.Web/Context/Support/WebSupportModule.cs +++ b/src/Spring/Spring.Web/Context/Support/WebSupportModule.cs @@ -175,10 +175,8 @@ namespace Spring.Context.Support /// /// /// - 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; } - ///

- /// Apply dependency injection stuff on the handler. - /// - /// the handler to be intercepted - /// the context responsible for configuring this handler - 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; - } - } - } - /// /// Disposes this instance /// diff --git a/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs b/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs index d78c190f..8e1b7743 100644 --- a/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs +++ b/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs @@ -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; } + + /// + /// Apply dependency injection stuff on the handler. + /// + /// the handler to be intercepted + /// the context responsible for configuring this handler + 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; + } + } + } } }