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 6167693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:33:27+00:00 2026-05-23T22:33:27+00:00

Regarding the Castle Automatic Transaction Management Facility; I’m having some difficulties getting operations to

  • 0

Regarding the Castle Automatic Transaction Management Facility; I’m having some difficulties getting operations to actually save to the database without flushing the session.

I’m using the following components
* NHibernate.dll v3.1.0.4000
* Castle.Core.dll v2.5.2.0
* Castle.Windsor.dll v2.5.3.0
* Castle.Facilities.NHibernateIntegration.dll v1.1.0.0
* Castle.Services.Transaction.dll v2.5.0.0
* Castle.Facilities.AutoTx.dll v2.5.1.0

I have followed the Castle documentation very closely and have not been able to resolve my issue.

My (web-)application follows the MVP pattern. The key parts of the (transactional) presenter-service are shown below:

<Transactional()> _
Public Class CampusEditPresenter
    Inherits BasePresenter(Of ICampusEditView)

    Public Sub New(ByVal view As ICampusEditView)
        MyBase.New(view)
    End Sub

    ...

    <Transaction(TransactionMode.Requires)> _
    Public Overridable Sub Save() Implements ICampusEditPresenter.Save

        ' Simplified
        Using session As ISession = _sessionManager.OpenSession()

            Dim campus As New Campus()

            campus.Code = _view.Code
            campus.ShortDescription = _view.ShortDescription
            campus.LongDescription = _view.LongDescription
            campus.StartDate = _view.StartDate
            campus.EndDate = _view.EndDate

            session.Save(campus)

        End Using

    End Sub

End Class

This presenter-service is registered in an installer:

container.Register( _
    Component.For(Of CampusEditPresenter) _
    .Interceptors(Of DebugLoggingInterceptor) _
    .LifeStyle.Transient)

and resolved by the view (in the base):

Public Class BasePage(Of TPresenter)
    Inherits Page

    Protected _presenter As TPresenter

    ...

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
        _presenter = _container.Resolve(Of TPresenter)(New With {Key .view = Me})
    End Sub

    ...

End Class

Public Class CampusEdit
Inherits BasePage(Of CampusEditPresenter)
    Implements ICampusEditView

    ...

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        _presenter.Save()
    End Sub

    ...

End Class

I have registered the NHibernate and Transaction facilities in an XML configuration file as follows:

<facility id="transaction" type="Castle.Facilities.AutoTx.TransactionFacility, Castle.Facilities.AutoTx" />
<facility id="nhibernate" type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration" isWeb="true" configurationBuilder="[removed].AutoConfigurationBuilder, [removed]">
    <factory id="nhibernate.factory">
    <settings>
            <item key="connection.driver_class">NHibernate.Driver.OracleClientDriver, NHibernate</item>
      <item key="connection.connection_string">[removed]</item>
      <item key="show_sql">false</item>
      <item key="dialect">NHibernate.Dialect.Oracle10gDialect, NHibernate</item>
      <item key="query.substitutions">true 1, false 0, yes 'Y', no 'N'</item>
      <item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</item>
      <item key="current_session_context_class">web</item>
      <item key="hbm2ddl.keywords">auto-quote</item>
        </settings>
    </factory>
</facility>

and I have registered the SessionWebModule Http module in my Web.config:

<httpModules>
    <add name="NHibernateSessionWebModule" type="Castle.Facilities.NHibernateIntegration.Components.Web.SessionWebModule, Castle.Facilities.NHibernateIntegration"/>
    ...
</httpModules>

Any ideas as to why this may not be working?

I can get everything working when I a) instansiate my own transactions from the ISession instance and maually commit these transactions, or if I b) use the Automatic Transaction Management AOP-mechanism AND manuall flush the session instance (though I shouldn’t have to manually do this).

I would have also thought that SessionWebModule IHttpModule (which follows the open-session-per-request pattern) would cause my entities to be persisted, but this doesnt seem to be happening…

  • 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-05-23T22:33:28+00:00Added an answer on May 23, 2026 at 10:33 pm

    So I worked out the TransactionInterceptor was not getting registerd on my components.

    After downloading the Castle.Facilities.AutomaticTransactionManagement source from github and stepping through, I found my issue and managed to resolve it.

    Basically the TransactionFacility adds a contributor, TransactionComponentInspector, to the ComponentModelBuilder, which allows for some additional configuration contribution whilst building the component. In the case of the TransactionComponentInspector, it looks for a “Transactional” class attribute on the component and if it exists it will register a TransactionInterceptor on the component. However, my components were never getting contributed to by the TransactionComponentInspector.

    To configure/register my components on the container, I use Installers. I configure the container itself using XML, which references these installers as well as any facilities (e.g. NHibernate-integration/logging etc.). Anyways, I believe it may have been some kind of ordering issue whereby my components might have been getting registered before the transaction facility. As such components registered before the TransactionFacility were not getting contributed-to by the TransactionComponentInspector and were therefore not getting a TransactionInterceptor registered on the component. Once I realised this I manually configured the container (with the correct order of things) and everything seemed to work!!!

    Now I’ve got to try and work out how to do this in my XML configuration. If I can’t, I guess I’ll dump this and go for fluent configuration of the container (e.g. in the global HttpApplication).

    [edit] see below:

    _container = New WindsorContainer()
    ' TransactionFacility must be registered before components.
    _container.AddFacility(Of TransactionFacility)()
    _container.Install(Configuration.FromXmlFile("Configs\services.xml"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Regarding TJvRichEdit and Delphi... How? Load/Save rtf (including text and images - not only
Regarding Delphi memory management, what are your design strategies ? What are the use
Hi I am attempting to use Castle windsor Nhibernate Facility with fluent Nhibernate and
Regarding to SQL performance. I have a scalar valued function for checking some specific
Regarding the same program as my question a few minutes ago ... I added
Regarding cross-site request forgery (CSRF) attacks, if cookies are most used authentication method, why
Regarding the classic test pattern of Arrange-Act-Assert , I frequently find myself adding a
Regarding separations of concerns only, are there advantages of using ASP.NET MVC instead of
Regarding the following C++ program: class Base { }; class Child : public Base
Regarding the worker pool, what happens when the computer restarts? Does the worker continue

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.