ActiveRecord Initialisation

10 views
Skip to first unread message

DKB

unread,
Sep 6, 2007, 10:08:36 PM9/6/07
to Castle Project Users
Hi,

I configured AR according to the online docs, specifically:

public void Application_Start(Object sender, EventArgs e)
{
BeginRequest += new EventHandler(OnBeginRequest);
EndRequest += new EventHandler(OnEndRequest);
}

However this didn't work which was surprising so I set some
breakpoints in my global application and observed the following events
in cronological order:

1) Constructor, OnStart
2) Constructor, OnBeginRequest (x1)
3) Constructor, OnBeginRequest (x13)

So 3 instances of the global application were created and the
OnBeginRequest events were sent to a different instance than the
OnStart events which explains why it didn't work. As soon as I changed
the code as follows everything started working:

public GlobalApplication()
{
BeginRequest += new EventHandler(OnBeginRequest);
EndRequest += new EventHandler(OnEndRequest);
}

But this does strike me as a very strange thing to be happening - any
ideas?

Cheers,

Dale

Fábio Batista

unread,
Sep 10, 2007, 5:56:05 PM9/10/07
to castle-pro...@googlegroups.com
I guess you are right: as far as I remember, the Application_Start
method is called only once, but many Application instances can be
created. So you basically need to hook the event on every instance.

I usually hook the events by overriding the HttpApplication.Init
method. It's called once per Application instance, just like the
constructor... But it's called after all modules were created, so I
guess it's safer to work there.


--
Fábio David Batista
fabio.dav...@gmail.com
http://nerd-o-matic.blogspot.com

Dale Burrell

unread,
Sep 10, 2007, 10:05:21 PM9/10/07
to castle-pro...@googlegroups.com
So just for my curiosity, why would there be more than one app instance
created?


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.485 / Virus Database: 269.13.14/999 - Release Date: 10/09/2007
17:43


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.485 / Virus Database: 269.13.14/999 - Release Date: 10/09/2007
17:43

Tim Haines

unread,
Sep 10, 2007, 11:15:00 PM9/10/07
to castle-pro...@googlegroups.com
" The ASP.NET runtime creates as many instances of application classes as needed to process requests simultaneously. For most applications, this number is limited to the number of threads and remains in the range of 1 through 100, depending on the hardware, server load, configuration, and so on. Many requests reuse application instances, and a free list of application instances is kept during periods of reduced load. Application instances are used in a thread-safe manner, that is, one request at a time. This has important implications:"

From http://support.microsoft.com/kb/312607
Reply all
Reply to author
Forward
0 new messages