dimanche 11 mai 2014

NHibernate - CodeConfig équivalent à tx:attribute-driven - Stack Overflow


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



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


0 commentaires:

Enregistrer un commentaire