热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP.NET&Spring.NET&NHibernate最佳实践(五)——第3章人事子系统(2)

3.4.人事子系统服务层(Service)部门服务接口(IDeptService.cs)usingSystem;usingGuushuuse.SalaryPrj.
3.4. 人事子系统服务层(Service)
部门服务接口(IDeptService.cs)
using  System;
using  Guushuuse.SalaryPrj.HR.DomainModel;
using  Guushuuse.SalaryPrj.HR.Dao;
using  System.Collections;

namespace  Guushuuse.SalaryPrj.HR.Service
{
    
/**//// 
    
/// 部门服务接口
    
/// 

    public interface IDeptService
    
{
        
void CreateDept(Dept dept);
        
void DeleteDept(Dept dept);
        IDeptDao DeptDao 
getset; }
        IList GetAllDepts();
        Dept GetDept(
int deptID);
        
void UpdateDept(Dept dept);
    }

}


部门服务类(DeptService.cs)
using  System;
using  System.Collections.Generic;
using  System.Text;
using  Guushuuse.SalaryPrj.HR.Dao;
using  Guushuuse.SalaryPrj.HR.DomainModel;
using  System.Collections;
using  Spring.Transaction.Interceptor;

namespace  Guushuuse.SalaryPrj.HR.Service
{
    
/**//// 
    
/// 部门服务类
    
/// 

    public class DeptService : IDeptService
    
{        
        
private IDeptDao _deptDao;

        
public IDeptDao DeptDao
        
{
            
get return _deptDao; }
            
set { _deptDao = value; }
        }


        
public DeptService()
        
{

        }


        [Transaction(ReadOnly 
= false)]
        
public void CreateDept(Dept dept)
        
{
            _deptDao.CreateDept(dept);
        }


        [Transaction(ReadOnly 
= false)]
        
public void UpdateDept(Dept dept)
        
{
            _deptDao.UpdateDept(dept);
        }


        [Transaction(ReadOnly 
= false)]
        
public void DeleteDept(Dept dept)
        
{
            _deptDao.DeleteDept(dept);
        }


        
public IList GetAllDepts()
        
{
            
return _deptDao.GetAllDepts();
        }


        
public Dept GetDept(int deptID)
        
{
            
return _deptDao.GetDept(deptID);
        }

    }

}


员工服务接口(IEmployeeService.cs)
using  System;
using  Guushuuse.SalaryPrj.HR.DomainModel;
using  Guushuuse.SalaryPrj.HR.Dao;
using  System.Collections;

namespace  Guushuuse.SalaryPrj.HR.Service
{
    
/**//// 
    
/// 员工服务接口
    
/// 

    public interface IEmployeeService
    
{
        
void CreateEmployee(Employee employee);
        
void DeleteEmployee(Employee employee);
        IEmployeeDao EmployeeDao 
getset; }
        IList GetAllEmployees();
        Employee GetEmployee(
int employeeID);
        
void UpdateEmployee(Employee employee);
    }

}


员工服务类(EmployeeService.cs)
using  System;
using  System.Collections.Generic;
using  System.Text;
using  Guushuuse.SalaryPrj.HR.Dao;
using  Guushuuse.SalaryPrj.HR.DomainModel;
using  System.Collections;
using  Spring.Transaction.Interceptor;

namespace  Guushuuse.SalaryPrj.HR.Service
{
    
/**//// 
    
/// 员工服务类
    
/// 

    public class EmployeeService : IEmployeeService
    
{        
        
private IEmployeeDao _employeeDao;

        
public IEmployeeDao EmployeeDao
        
{
            
get return _employeeDao; }
            
set { _employeeDao = value; }
        }


        
public EmployeeService()
        
{

        }


        [Transaction(ReadOnly 
= false)]
        
public void CreateEmployee(Employee employee)
        
{
            _employeeDao.CreateEmployee(employee);
        }


        [Transaction(ReadOnly 
= false)]
        
public void UpdateEmployee(Employee employee)
        
{
            _employeeDao.UpdateEmployee(employee);
        }


        [Transaction(ReadOnly 
= false)]
        
public void DeleteEmployee(Employee employee)
        
{
            _employeeDao.DeleteEmployee(employee);
        }


        
public IList GetAllEmployees()
        
{
            
return _employeeDao.GetAllEmployees();
        }


        
public Employee GetEmployee(int employeeID)
        
{
            
return _employeeDao.GetEmployee(employeeID);
        }

    }

}


服务定位类(ServiceLocator.cs)
using  System;
using  System.Collections.Generic;
using  System.Text;
using  Spring.Context;
using  Spring.Context.Support;

namespace  Guushuuse.SalaryPrj.HR.Service
{
    
/**//// 
    
/// 服务定位类
    
/// 

    public class ServiceLocator
    
{
        
private static IApplicationContext _ctx;

        
static ServiceLocator()
        
{
            _ctx 
= ContextRegistry.GetContext();
        }


        
public static IDeptService DeptService
        
{
            
get
            
{
                IDeptService deptService 
= _ctx["deptService"as IDeptService;

                
return deptService;
            }

        }


        
public static IEmployeeService EmployeeService
        
{
            
get
            
{
                IEmployeeService employeeService 
= _ctx["employeeService"as IEmployeeService;

                
return employeeService;
            }

        }

    }

}


修改Config/Guushuuse.SalaryPrj.HR.config文件,新增object
< object  id ="deptService"  type ="Guushuuse.SalaryPrj.HR.Service.DeptService, Guushuuse.SalaryPrj.HR" >
    
< property  name ="DeptDao"  ref ="deptDao"   />
  
object >

  
< object  id ="employeeService"  type ="Guushuuse.SalaryPrj.HR.Service.EmployeeService, Guushuuse.SalaryPrj.HR" >
    
< property  name ="EmployeeDao"  ref ="employeeDao"   />
  
object >

推荐阅读
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了使用PHP实现断点续传乱序合并文件的方法和源码。由于网络原因,文件需要分割成多个部分发送,因此无法按顺序接收。文章中提供了merge2.php的源码,通过使用shuffle函数打乱文件读取顺序,实现了乱序合并文件的功能。同时,还介绍了filesize、glob、unlink、fopen等相关函数的使用。阅读本文可以了解如何使用PHP实现断点续传乱序合并文件的具体步骤。 ... [详细]
  • 本文讨论了在Spring 3.1中,数据源未能自动连接到@Configuration类的错误原因,并提供了解决方法。作者发现了错误的原因,并在代码中手动定义了PersistenceAnnotationBeanPostProcessor。作者删除了该定义后,问题得到解决。此外,作者还指出了默认的PersistenceAnnotationBeanPostProcessor的注册方式,并提供了自定义该bean定义的方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
author-avatar
玩在青岩堡欢乐长桌宴_840
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有