Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:15:15+00:00 2026-06-17T12:15:15+00:00

Yes. this is an issue related to how i ask Castle Windsor to resolve

  • 0

Yes. this is an issue related to how i ask Castle Windsor to resolve my ISession, but i have reread the code like 5 times, and can’t still figure out what is wrong with it.

Below is my rather standard NHibernate facility, except for the last 2 components which I have registered:

 public class NHibernateFacility : AbstractFacility
    {
        protected override void Init()
        {
            var config = new Configuration().Configure();
            Kernel.Register(
                Component.For<ISessionFactory>()
                    .UsingFactoryMethod((kernel, context) => config.BuildSessionFactory()),
                Component.For<ISession>()
                    .UsingFactoryMethod((kernel, context) => kernel.Resolve<ISessionFactory>().OpenSession())
                    .LifestylePerWebRequest(),
                     Component.For<IStatelessSession>()
                    .UsingFactoryMethod((kernel, context) => kernel.Resolve<ISessionFactory>().OpenStatelessSession())
                    .LifestylePerWebRequest(),
                    Component.For<StatefulSessionWrapper>().LifestylePerWebRequest(),
                    Component.For<StatelessSessionWrapper>().LifestylePerWebRequest()
                );
        }
    }

The StatefulSessionWrapper/StatelessSessionWrapper serve as a … wrapper for ISession/IStateless session like this:

public class StatefulSessionWrapper : ISessionWrapper
    {
        public StatefulSessionWrapper(ISession session)
        {
            this.Session = session;
        }

        private readonly ISession Session;

        #region ISessionWrapper Members

        public ITransaction BeginTransaction()
        {
            return Session.BeginTransaction();
        }

        public ITransaction BeginTransaction(IsolationLevel isolationLevel)
        {
            return Session.BeginTransaction(isolationLevel);
        }

        public ITransaction Transaction { get { return Session.Transaction; } }

        public bool IsConnected
        {
            get { return Session.IsConnected; }
        }

        public bool IsOpen
        {
            get { return Session.IsOpen; }
        }

        #endregion
    }

This way, I can use a single action filter, which only handles the transaction part of the NHibernate Session:

public class NHibernateActionFilter<T> : Castle.MonoRail.Framework.IFilter where T:ISessionWrapper
    {
        private readonly T NHibernateSession;

        public NHibernateActionFilter(T session)
        {
            if (session != null)
                NHibernateSession = session;
            else
                throw new NullReferenceException("Session is null");
        }

        #region IFilter Members

        public bool Perform(ExecuteWhen exec, IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            if (exec == ExecuteWhen.BeforeAction)
            {
                NHibernateSession.BeginTransaction();
                return true;
            }
            if (exec == ExecuteWhen.AfterAction)
            {
                if (NHibernateSession.Transaction == null || !NHibernateSession.Transaction.IsActive)
                    return false;
                if (context.LastException != null)
                {
                    NHibernateSession.Transaction.Rollback();
                    return false;
                }
                else
                {
                    NHibernateSession.Transaction.Commit();
                    return true;
                }

            }
            return false;
        }

        #endregion
    }

And use it simply as this:

    [Filter(ExecuteWhen.Always, typeof(NHibernateActionFilter<StatefulSessionWrapper>), ExecutionOrder = 1)]
    [Filter(ExecuteWhen.BeforeAction, typeof(AuthenticationFilter), ExecutionOrder = 2)]
    [Layout("Default"), Rescue("Default")]
    public abstract class NHibernateController : SmartDispatcherController
    {
        public NHibernateController(ISession session)
        {
            this.NHibernateSession = session;
        }

        protected readonly ISession NHibernateSession;
        ..................

The only problem?

This is the rescue page. See the exception details below

ObjectDisposedException

Message: Session is closed! Object name: ‘ISession’.

StackTrace: at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed()
in p:\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line
207 at
NHibernate.Impl.AbstractSessionImpl.CheckAndUpdateSessionStatus() in
p:\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 199
at NHibernate.Impl.SessionImpl.BeginTransaction() in
p:\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1456 at
ADAutoTotal.Monorail.StatefulSessionWrapper.BeginTransaction() in
C:\Dropbox\Projects\ADAutoTotal\ADAutoTotal.Monorail\StatefulSessionWrapper.cs:line
23 at
ADAutoTotal.Monorail.NHibernateActionFilter`1.Perform(ExecuteWhen
exec, IEngineContext context, IController controller,
IControllerContext controllerContext) in
C:\Dropbox\Projects\ADAutoTotal\ADAutoTotal.Monorail\NHibernateActionFilter.cs:line
31 at
Castle.MonoRail.Framework.Controller.ProcessFilter(ExecuteWhen when,
FilterDescriptor desc) in
C:\Dropbox\Projects\Monorail\castleproject-MonoRail-98c93ac\castleproject-MonoRail-98c93ac\MR2\src\Castle.MonoRail.Framework\Controller.cs:line 2099 at
Castle.MonoRail.Framework.Controller.ProcessFilters(IExecutableAction
action, ExecuteWhen when) in
C:\Dropbox\Projects\Monorail\castleproject-MonoRail-98c93ac\castleproject-MonoRail-98c93ac\MR2\src\Castle.MonoRail.Framework\Controller.cs:line 2054 at
Castle.MonoRail.Framework.Controller.RunBeforeActionFilters(IExecutableAction
action, Boolean& cancel) in
C:\Dropbox\Projects\Monorail\castleproject-MonoRail-98c93ac\castleproject-MonoRail-98c93ac\MR2\src\Castle.MonoRail.Framework\Controller.cs:line 1953 at
Castle.MonoRail.Framework.Controller.RunActionAndRenderView() in
C:\Dropbox\Projects\Monorail\castleproject-MonoRail-98c93ac\castleproject-MonoRail-98c93ac\MR2\src\Castle.MonoRail.Framework\Controller.cs:line 1622

So, it’s obvious that the NHibernateActionFilter gets a closed session. But according to me, it shouldn’t. Halp.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:15:16+00:00Added an answer on June 17, 2026 at 12:15 pm

    Well, it turns out that i forgot to add to my action filter their proper lifestyles, therefore letting Windsor making them singleton…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Before anyone says anything Yes this was homework but i have already turned it
Yes, I know this question has been asked a lot of times, but I
I have a universal app but this issue seems to only relate to the
I ran into this issue quite a few times. Let's say I have a
I know the Sales pitch answer is yes to this question, but is it
Yes, this is a programming-related question, if a little indirectly. For better or worse,
Yes, I know this question has been asked before, but I can't find an
Yes I know, this title isn't really helpfull but this is the exact problem.
As playorm supports ManytoMany, I have two questions related to this: How does the
I have an issue in which outdated code removed long ago code in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.