Results 1 to 4 of 4

Thread: Controller with Session scope becomes null

  1. #1
    Join Date
    Sep 2006
    Posts
    12

    Default Controller with Session scope becomes null

    Hello,

    I have a web site running on a public web host. It has been running with no problems for 2 days.
    Today, the home page, which tries to access the "Controller" property, is failing with a null pointer error, and would not recover from this error.

    It seems that the Controller (declared with 'session' scope, and which holds the User Session's data) is injected as null by Spring after certain period of time.

    I was expecting Spring to create a new instance of the Controller whenever the session expires, rather than holding a reference to something that is now null.
    (unless the problem lies somewhere else)

    The following is the relevant part of my SPring Configuration file:
    . . .
    <!--Controller -->
    <object id="OrielController" type="Oriel.Prototype.Controllers.OrielController" scope="session" >
    <property name="AppContainer" ref="AppContainer" />
    <property name="LogInAttempt" ref="LogInAttempt"/>
    </object>

    <!-- Base page for all web pages -->
    <object id="standardPage" abstract="true" init-method="DependenciesInjected">
    <property name="PageController" ref="OrielController" />
    <property name="MasterPageFile" value="~/StandardTemplate.master" />
    <property name="AppContainer" ref="AppContainer" />
    </object>

    <!-- Base page for all admin web pages -->
    <object id="adminPage" abstract="true" init-method="DependenciesInjected">
    <property name="PageController" ref="OrielController" />
    <property name="MasterPageFile" value="~/Admin/AdminTemplate.master" />
    <property name="AppContainer" ref="AppContainer" />
    </object>

    <!-- Non Admin Pages -->
    <object type="~/HomePage.aspx" parent="standardPage" >
    <property name="Results">
    <dictionary>
    <entry key="RoleTypeSelected" value="transfer:SearchResults.aspx"/>
    <entry key="SearchedJobs" value="transfer:SearchResults.aspx"/>
    <entry key="ViewJob" value="transfer:job-details.aspx"/>
    <entry key="UploadCV" value="redirect:submit-cv.aspx"/>
    </dictionary>
    </property>
    </object>


    . . .

    By the way, all pages using 'standardPage' as their abstract class are getting the same error. However, all pages inheriting from 'adminPage' gets a valid Controller instance.

    Could anybody please help me out with this problem?
    Thanks very much in advance,
    Sebastian

  2. #2
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi,

    Are you using one of the latest nightly builds?

    You don't have any logfiles from the time this problem occured for the first time, do you? This would help much clearing up, what has happened.

    Basically "session"-scope is designed to work as you are expecting. I've been running session-scoped objects on my own websites for several months now - but didn't face this problem. Maybe you can find a way to reproduce the error?

    cheers,
    Erich

  3. #3
    Join Date
    Sep 2006
    Posts
    12

    Default

    Hi Erich,

    Many thanks for your time.
    Unfortunately, I haven't instrumented the application yet.
    I've been doing a (very) little research on this, and it seems that when the page/control has AutoEventWiring set to true (which I think is the default in ASP 2, unlike ASP 1) the injection of dependencies is not done upon PostBacks.
    Not sure of this, but certainly the injection of dependencies is not done unconditionally for every request.

    I've added this hack to my base page, and the error did not happen again:

    private void EnsureControllerIsAssigned()
    {
    if (!_dependenciesInjected) return;

    if (Controller != null) return;

    if (Session["OrielController.spring"] != null)
    {
    Controller = Session["OrielController.spring"];
    return;
    }

    //TODO: [Seb] Log stack trace to understand why we got to this point.
    // Also, consider creating a new controller if page does not require autentication
    throw new ApplicationException("Oriel Controller not found in session");
    }


    THis method is called on the OnLoad event of the base page.
    The fact that the error is not happening confirm what I've seen in Spring code: the session scope of the controller works fine. Is the injection of the controller into the page/control what is not being done.

    Hope this makes sense.

    Thanks again,
    Sebastian

  4. #4
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi Sebastian,

    Please give one of the latest nightly builds a try. Altough I can't imagine a particular reason for your problem yet, I know, that Web DI had it's weaknesses.
    Therefore I've completely reworked DI during last week - with the new implementation you are guaranteed to have dependencies injected right before Control.OnInit() is called. It works even with DataBinding on Repeaters etc. Technically speaking, DI is now done during Control.AddedControl(). You even don't have to derive from Spring.Web.UI.Page/.Control now.

    Since we're releasing Version 1.1 Preview 3 this weekend, give that one a try and let us know, if the problem persist. If it's really only a DI problem, it should be gone.

    cheers,
    Erich

Posting Permissions

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