热门标签 | 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 >

推荐阅读
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • 本文介绍了使用PHP实现断点续传乱序合并文件的方法和源码。由于网络原因,文件需要分割成多个部分发送,因此无法按顺序接收。文章中提供了merge2.php的源码,通过使用shuffle函数打乱文件读取顺序,实现了乱序合并文件的功能。同时,还介绍了filesize、glob、unlink、fopen等相关函数的使用。阅读本文可以了解如何使用PHP实现断点续传乱序合并文件的具体步骤。 ... [详细]
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社区 版权所有