Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using Spring.NET AOP + NHibernate you can write your repository class as normal and configure your transactions in custom XML file:</p> <pre><code>public class CustomerService : ICustomerService { private readonly ICustomerRepository _customerRepository; private readonly IOrderRepository _orderRepository; public CustomerService( ICustomerRepository customerRepository, IOrderRepository orderRepository) { _customerRepository = customerRepository; _orderRepository = orderRepository; } public int CreateOrder(Order o, Customer c) { // Do something with _customerRepository and _orderRepository } } </code></pre> <p>In the XML file you select which methods you would like to be executed inside a transaction:</p> <pre><code> &lt;object id="TxProxyConfigurationTemplate" abstract="true" type="Spring.Transaction.Interceptor.TransactionProxyFactoryObject, Spring.Data"&gt; &lt;property name="PlatformTransactionManager" ref="HibernateTransactionManager"/&gt; &lt;property name="TransactionAttributes"&gt; &lt;name-values&gt; &lt;add key="Create*" value="PROPAGATION_REQUIRED"/&gt; &lt;/name-values&gt; &lt;/property&gt; &lt;/object&gt; &lt;object id="customerService" parent="TxProxyConfigurationTemplate"&gt; &lt;property name="Target"&gt; &lt;object type="MyNamespace.CustomerService, HibernateTest"&gt; &lt;constructor-arg name="customerRepository" ref="customerRepository" /&gt; &lt;constructor-arg name="orderRepository" ref="orderRepository" /&gt; &lt;/object&gt; &lt;/property&gt; &lt;/object&gt; </code></pre> <p>And in your code you obtain an instance of the CustomerService class like this:</p> <pre><code>ICustomerService customerService = (ICustomerService)ContextRegistry .GetContent() .GetObject("customerService"); </code></pre> <p>Spring.NET will return you a proxy of the CustomerService class that will apply a transaction when you call CreateOrder method. This way there's no transaction specific code inside your service classes. AOP takes care of it. For more details you can take a look at the documentation of <a href="http://www.springframework.net/doc-latest/reference/html/orm.html#orm-hibernate" rel="noreferrer">Spring.NET</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload