4
votes

I'm using CodeConfig as opposed to XML files for Spring.NET using Fluent NHibernate to read/write to the database.

But for transaction management, I still want to use Spring's [Transaction] attribute on my service methods. In XML I would do

<tx:attribute-driven/>

I can get around this by handling the transaction myself like this

public WorkItem SaveWorkItem(WorkItem workItem)
{
    using (ITransaction tx = CurrentSession.BeginTransaction())
    {
        CurrentSession.SaveOrUpdate(workItem);
        tx.Commit();
    }
    return workItem;
}

But is there a CodeConfig-only way of allowing this using an attribute instead, like this:

[Transaction]
public WorkItem SaveWorkItem(WorkItem workItem)
{
    CurrentSession.SaveOrUpdate(workItem);
    return workItem;
}

Thanks

1
Did you get it working with attribute? - is_this_the_way
I didn't I'm afraid (and it doesn't look like there's much activity going on in Spring.NET land any more, sadly). I think I ended up using NHibernate's transactions instead. - Richard
OK, I am thinking of defining custom transaction advice aspect. - is_this_the_way

1 Answers