views:

339

answers:

2

Hello,
I'm trying to get started with Castle ActiveRecord but I'm stuck trying to make it work in an ASP.NET (MVC, if it matters) application.
In fact I'm getting an ObjectDisposedException during a query with the following message:

Session is closed!
Object name: 'ISession'.

I'm initializing ActiveRecord from an XML file (as shown in the getting started) of which the contents are:


<?xml version="1.0" encoding="utf-8" ?>

<activerecord isWeb="true" isDebug="true" threadinfotype="Castle.ActiveRecord.Framework.Scopes.HybridWebThreadScopeInfo, Castle.ActiveRecord">

  <config>
    <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="dialect" value="NHibernate.Dialect.MsSql2008Dialect" />
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="connection.connection_string" value="Data Source=.\SQLEXPRESS;Initial Catalog=testDB;Integrated Security=SSPI" />
    <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
    <add key="show_sql" value="true" />
    <add key="default_schema" value="testDB.dbo" />
  </config>

</activerecord>

Unfortunately mostly due to lack of documentation and my complete ignorance regarding Castle Windsor I'm not able to find out how should I configure it to make it work, so I'd be thankful if any of you could tell me what's missing or what's wrong.

Thanks in advance

Edit: I should probably specify that this error occurs on a thread which I spawn in Application_Start and which is in charge of running certain maintenance tasks.

+1  A: 

Use a SessionScope.

In Request___Start, create a new SessionScope() and dispose it in Request_End.

MZywitza
Could you please add more information or some example code?Thanks
emaster70
A: 

In Your ApplicationStart do something like:

void Application_Start(...)  {
    using( SessionScope session = new SessionScope() ) {
        // Your Startup Logic here
        session.Flush();
    }
}
Thomas Schreiner
won't work, emaster70 says it's on another thread
Mauricio Scheffer
If the ActiveRecord stuff is Thread Specific, why not run the ActiveRecord.Initialize(...) again on the new Thread?
Thomas Schreiner
ActiveRecord.Initialize() is not thread specific, it's appdomain-wide
Mauricio Scheffer