SSH.net之Service層

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   使用   sp   for   

一、建立一個項目,命名為:Service

二、添加介面及其實現

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Model;namespace Service{    public interface IUserService    {        object Save(Users entity);    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Model;namespace Service{    public class UserService:IUserService    {        public object Save(Users entity)        {            throw new NotImplementedException();        }    }}

 

由於用到Model層中Users對象,所以要引入一下項目Model,然後

 1 using Model; 

 二、設定檔

 

<?xml version="1.0" encoding="utf-8" ?><objects xmlns="http://www.springframework.net">    <object id="transactionManager"          type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate21">        <property name="DbProvider" ref="DbProvider"/>        <!--HibernateTransactionManager通過注入sessionfactory.        然後在得到session,把session封裝成SessionHolder(),並通過threadlocal來對象的實現和線程的綁定(threadlocal實現重點)        最後到線程中的session取得的Transaction-->        <property name="SessionFactory" ref="NHibernateSessionFactory"/>    </object>    <!-- 事務攔截器,啟用交易管理員所必須的 -->    <!-- Spring.net使用TransactionInterceptor聲明式事物配置-->    <object id="transactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">        <property name="TransactionManager" ref="transactionManager"/>        <property name="TransactionAttributeSource">            <object type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data"/>        </property>    </object>    <!--設定TransactionProxyFactoryObject事物代理,添加需要攔截的方法-->    <!--如果你不喜歡使用特性來標註事務([Transaction]),Spring.NET為NHibernate提供的事務代理是 TransactionProxyFactoryObject。-->    <object id="BaseTransactionManager"  type="Spring.Transaction.Interceptor.TransactionProxyFactoryObject, Spring.Data" abstract="true">        <!--spring擷取hibernate的事物管理-->        <property name="PlatformTransactionManager" ref="transactionManager"/>        <property name="TransactionAttributes">            <name-values>                <add key="Save*" value="PROPAGATION_REQUIRED"/>                <!--key屬性為Save*,意思是攔截所有以Save開頭的方法-->                <add key="Set*" value="PROPAGATION_REQUIRED"/>                <add key="Finish*" value="PROPAGATION_REQUIRED"/>                <add key="Update*" value="PROPAGATION_REQUIRED"/>                <add key="Delete*" value="PROPAGATION_REQUIRED"/>                <add key="Add*" value="PROPAGATION_REQUIRED"/>                <add key="Get*" value="PROPAGATION_SUPPORTS,readOnly"/>                <add key="Find*" value="PROPAGATION_SUPPORTS,readOnly"/>                <add key="Load*" value="PROPAGATION_SUPPORTS,readOnly"/>                <add key="*" value="PROPAGATION_REQUIRED"/>            </name-values>        </property>    </object>    <!--為rolesService.cs類添加TransactionProxyFactoryObject事物代理-->    <object id="rolesService" parent="BaseTransactionManager">        <!--將 TransactionProxyFactoryObject的 Target屬性注入業務處理層的類,這樣Spring.NET會為該類封裝上事務-->        <property name="Target">            <object type="Serivce.rolesService,Manager">                <property name="RolesDAO" ref="dao.roles"/>            </object>        </property>    </object>    <object id="UsersManager" parent="BaseTransactionManager">        <property name="Target">            <object type="Manager.UsersManager,Manager">                <property name="UsersDAO" ref="dao.users"/>            </object>        </property>    </object>    <object id="PermissionManager" parent="BaseTransactionManager">        <property name="Target">            <object type="Manager.PermissionManager,Manager">                <property name="PermissionDAO" ref="dao.permission"/>            </object>        </property>    </object></objects>

 

 

最後,設定設定檔屬性:

SSH.net之Service層

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.