This project is read-only.

i'm lost on startup

Aug 13, 2010 at 12:12 AM

Startup() seems to be getting called on each and every request.

I thought this was an application startup, only called once?

here's my setup:

global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="Generic.Mvc.GenericApplication" Language="C#" %>

GenericApplication.cs:

using Generic.Mvc.AutoMapper;
using MvcTurbine.ComponentModel;
using MvcTurbine.Web;
using MvcTurbine.StructureMap;
using StructureMap;

namespace Generic.Mvc
{
    public class GenericApplication : TurbineApplication
    {
        /// <summary>
        /// Performs any startup processing.
        /// </summary>

//NOTE THIS IS GETTING CALLED ON EACH AND EVERY REQUEST
        public override void Startup()
        {
            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
            AutoMapperConfiguration.Configure();
            var container = CreateContainer();
            ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator(container));
        }

        public virtual IContainer CreateContainer()
        {
            ObjectFactory.Initialize(DefaultInitialization);
            return ObjectFactory.Container;
        }

        private static void DefaultInitialization(IInitializationExpression expression)
        {
        }

        protected void Application_EndRequest()
        {
            ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
        }

        /// <summary>
        /// Shuts down the <see cref="P:MvcTurbine.Web.TurbineApplication.CurrentContext"/> and handles all pieces of cleanup.
        /// </summary>
        protected override void ShutdownContext()
        {
            CurrentContext = null;
            ServiceLocator = null;
        }    }
}

 

Default.aspx:

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace Generic.Web
{
    public partial class _Default : Page
    {
        public void Page_Load(object sender, System.EventArgs e)
        {
            // Change the current path so that the Routing handler can correctly interpret
            // the request, then restore the original path so that the OutputCache module
            // can correctly process the response (if caching is enabled).

            string originalPath = Request.Path;
            HttpContext.Current.RewritePath(Request.ApplicationPath, false);
            IHttpHandler httpHandler = new MvcHttpHandler();
            httpHandler.ProcessRequest(HttpContext.Current);
            HttpContext.Current.RewritePath(originalPath, false);
        }
    }
}

Aug 13, 2010 at 1:29 PM

Startup is run once during Application_Start, as in the code below:

http://github.com/lozanotek/mvcturbine/blob/master/src/Engine/MvcTurbine.Web/TurbineApplication.cs#L77

If Startup is being fired more than once, then Application_Start must be fired more than once, but I wouldn't say that's in MvcTurbine's scope.  Have you tried overriding Application_Start to see when it is being fired?  

Coordinator
Sep 7, 2010 at 3:17 PM

Hi @alan79,

Sorry for being MIA on this discussion, but what @darrencauthon mentions is how the system runs. Does the issue still exist?  

Sep 8, 2010 at 4:00 AM

no the issue doesn't exist anymore.

i backtracked a bit and don't have the Application_Start firing on every request now.

i must have messed it up somewhere.

Sep 8, 2010 at 4:02 AM

hi,
thanks for the followup.
i was following how one of the issues discussed setting up for StructureMap as the IOC.
i must have mucked something up and went back to that initial code and got it all working again.
alan
----- Original Message -----
From: [email removed]
To: [email removed]
Sent: Tuesday, September 07, 2010 7:17 AM
Subject: Re: i'm lost on startup [mvcturbine:223425]

From: jglozano

Hi @alan79,

Sorry for being MIA on this discussion, but what @darrencauthon mentions is how the system runs. Does the issue still exist?