Results 1 to 2 of 2

Thread: Injection working, but page gets instantiated *again* w/o injection

  1. #1
    Join Date
    May 2013
    Posts
    4

    Default Injection working, but page gets instantiated *again* w/o injection

    I've based my project on the Northwind example, but I must be doing something wrong. I'm having Spring construct a DAO object and inject it into an ASP page, which it does, but I see that the same page gets constructed by IIS (at least that's what I'm assuming), without the benefit of Spring's injection, and it's that latter page that gets run, throwing an exception when the DAO object is null.

    The page, WorkFlowDetail.aspx, inherits from a base class called BasePage1 (though I've tried it w/o the inheritance as well). BasePage1 has a public property for the DAO, giving us something like this:

    BasePage1.vb:

    Code:
    Public Class BasePage1
        Inherits System.Web.UI.Page
    
        Private _wfdao As IWfDao
        Public Property wfDao As IWfDao
            Get
                Return _wfdao
            End Get
            Set(value As IWfDao)
                _wfdao = value
            End Set
        End Property
    End Class
    WorkFlowDetail.aspx.vb:

    Code:
    Public Class WorkFlowDetail
        Inherits BasePage1
    End Class
    Web.xml:

    Code:
      <object type="WorkFlowDetail.aspx">
        <property name="wfDao" ref="wfDao" />
        <property name="SubmissionService" ref="SubmissionService" />
      </object>
    Web.config:

    Code:
    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          </sectionGroup>
        </sectionGroup>
        <sectionGroup name="spring">
          <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
          <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
          <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" requirePermission="false"/>
        </sectionGroup>
        <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache" />
      </configSections>
    
      <spring>
        <parsers>
          <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
          <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
        </parsers>
        <context annotation-config="">
          <resource uri="assembly://MyApp.Dao/MyApp.Dao.Dao.NHibernate/Dao.xml" />
          <resource uri="~/Config/Aspects.xml" />
          <resource uri="~/Web.xml" />
        </context>
        <objects xmlns="http://www.springframework.net" xmlns:tx="http://www.springframework.net/tx">
          <tx:attribute-driven/>
        </objects>
      </spring>
    
      <system.web>
        <profile enabled="true" defaultProvider="SqlProvider">
          <providers>
            <clear />
            <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MembershipConnectionString" applicationName="iview" description="SqlProfileProvider for iview" />
          </providers>
          <properties>
            <add name="productCartEmail" type="System.String" />
          </properties>
        </profile>
    
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
        <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="60" />
        <authentication mode="Forms">
          <forms loginUrl="login.aspx" name=".form1" />
        </authentication>
        <authorization>
          <deny users="?" />
        </authorization>
        <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MembershipConnectionString" applicationName="iview" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false" passwordFormat="Encrypted" />
          </providers>
        </membership>
        <roleManager defaultProvider="SqlRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="60" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
          <providers>
            <clear />
            <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MembershipConnectionString" applicationName="iview" />
          </providers>
        </roleManager>
        <customErrors mode="RemoteOnly" defaultRedirect="~/message.aspx">
          <error statusCode="403" redirect="../topSite/message.htm" />
          <error statusCode="404" redirect="../topSite/message.htm" />
        </customErrors>
    
        <httpHandlers>
          <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
          <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
        </httpHandlers>
        <httpModules>
          <add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
          <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32" />
        </httpModules>
      </system.web>
      
      <system.webServer>
        <handlers>
          <add name="SpringPageHandler" preCondition="integratedMode" verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
          <add name="SpringWebServiceHandler" verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
          <add name="SpringContextMonitor" verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
          <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
        </handlers>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
          <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
      </system.webServer>
      
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="Ingredients.Service1AspNetAjaxBehavior">
              <enableWebScript />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <services>
          <service name="Ingredients.Service1">
            <endpoint address="" behaviorConfiguration="Ingredients.Service1AspNetAjaxBehavior" binding="webHttpBinding" contract="Ingredients.Service1" />
          </service>
        </services>
      </system.serviceModel>
      
      <appSettings>
        <!-- Other App Settings -->
        <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory" />
        <add key="maxBytesAttachments" value="5000000"/>
        <add key="ExpirationTimeInMinutes" value="20"/>
        <add key ="MaxReceivedMessageSize" value="1073741824"/>
        <add key ="MaxBufferSize" value="1073741824"/>
        <add key ="MaxBufferPoolSize" value="1073741824"/>
        <add key ="EndpointAddress" value="http://localhost:20000/WcfRestServices/json" />
      </appSettings>
    </configuration>
    Setting a couple of strategic breakpoints I find that WorkFlowDetail.aspx gets constructed first by Spring and the DAO object is injected. It shows up in the debugger's Watch list as a "(ASP.workflowdetail_aspx)" and the stack looks like this:
    Code:
    [External Code] 
    Spring.Web.dll!Spring.Util.VirtualEnvironment.HttpRuntimeEnvironment.CreateInstanceFromVirtualPath(string virtualPath, System.Type requiredBaseType) Line 409 + 0x12 bytes  C#
    Spring.Web.dll!Spring.Util.VirtualEnvironment.CreateInstanceFromVirtualPath(string virtualPath, System.Type requiredBaseType) Line 515 + 0x44 bytes C#
    Spring.Web.dll!Spring.Objects.Factory.Support.WebObjectUtils.CreateHandler(string pageUrl) Line 156 + 0x20 bytes    C#
    Spring.Web.dll!Spring.Objects.Factory.Support.WebObjectUtils.CreatePageInstance(string pageUrl) Line 105 + 0xc bytes    C#
    ...
    [External Code]
    Then the constructor is called again. This time the object shows up as "scheduleSite.WorkFlowDetail" in the debugger's Watch list and the stack just shows
    Code:
    [External Code]
    UPDATE:

    First-of-all, the page is being constructed more than just twice; I thought only twice because it was throwing an exception on the second time, but I find that if I get past there I hit the constructor 3-4 more times.

    Second, I suspect that my problems stem from a misconfiguration of Web.config. I can't base myself precisely on Northwind because Northwind is targeting .NET 3.5 whereas we're targeting 4.0 and IIS7.0 in Integrated mode. I've done the configuration for that as I understand it from examples in this forum and elsewhere, but nothing seems to work.

  2. #2
    Join Date
    May 2013
    Posts
    4

    Default

    The problem turned out to be with the way we were setting the DataSources of our Telerik RadGrid controls. We were assigning them in the ASP code, which caused the Telerik code to re-instantiate the page for each assignment (you'll forgive me for not going into the details of why Telerik does this).

    We got around it by using the controls' OnNeedDataSource event to have the DataSources set later on

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •