Hi everybody,

I have a generic repository base class for my NHibernate repositories,
Repository<TEntity>, in which I want to provide a couple of standard
methods within transactions. I'm using the
Castle.Services.Transaction, together with Castle.Facilities.AutoTx
and Castle.Facilities.NHibernate

    public abstract class Repository<TEntity> where TEntity :
IEntity // common entity interface that declares int ID { get; }
    {
        protected Func<ISession> SessionGetter;

        public Repository(Func<ISession> sessionGetter)
{ SessionGetter = sessionGetter; }

        [Transaction(Mode = TransactionScopeOption.Required)]
        protected virtual void Save(TEntity entity)
        {
            var session = sessionGetter();
            session.Save(entity);
        }
    }

When I call this method from a repository implementation, I get an
exception saying
"Castle.Facilities.AutoTx.MissingTransactionException : No transaction
in context when trying to instantiate model 'NHibernate.ISession' for
resolve type 'NHibernate.ISession'. If you have verified that your
call stack contains a method with the [Transaction] attribute, then
also make sure that you have registered the AutoTx Facility." If I put
the attribute on the calling method, everything works - but I want to
be able to throw and catch exceptions in the calling methods without
having to worry about the transaction committing or rolling back, so
I'd like to isolate the db work in small methods that orchestrate a
transaction, do its job and then commits (or rolls back and bubbles
the exception).

I am not familiar enough with the castle project to really understand
what's going on behind the scenes here, and the documentation I've
found (here: http://docs.castleproject.org/Windsor.ATM-Facility.ashx)
is pretty sparse and mildly outdated.

Please advise if this is doable - and if so, how. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to