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

推荐阅读
  • 本文介绍如何使用阿里云的fastjson库解析包含时间戳、IP地址和参数等信息的JSON格式文本,并进行数据处理和保存。 ... [详细]
  • 本文介绍如何使用 NSTimer 实现倒计时功能,详细讲解了初始化方法、参数配置以及具体实现步骤。通过示例代码展示如何创建和管理定时器,确保在指定时间间隔内执行特定任务。 ... [详细]
  • 本文探讨了浏览器的同源策略限制及其对 AJAX 请求的影响,并详细介绍了如何在 Spring Boot 应用中优雅地处理跨域请求,特别是当请求包含自定义 Headers 时的解决方案。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文介绍如何使用Objective-C结合dispatch库进行并发编程,以提高素数计数任务的效率。通过对比纯C代码与引入并发机制后的代码,展示dispatch库的强大功能。 ... [详细]
  • 在使用 DataGridView 时,如果在当前单元格中输入内容但光标未移开,点击保存按钮后,输入的内容可能无法保存。只有当光标离开单元格后,才能成功保存数据。本文将探讨如何通过调用 DataGridView 的内置方法解决此问题。 ... [详细]
  • 一个登陆界面
    预览截图html部分123456789101112用户登入1314邮箱名称邮箱为空15密码密码为空16登 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 本文探讨了在不使用服务器控件的情况下,如何通过多种方法获取并修改页面中的HTML元素值。除了常见的AJAX方式,还介绍了其他可行的技术方案。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
  • 本文详细介绍了如何使用 HTML 和 CSS 对文件上传按钮进行样式美化,使用户界面更加友好和美观。 ... [详细]
  • 当unique验证运到图片上传时
    2019独角兽企业重金招聘Python工程师标准model:public$imageFile;publicfunctionrules(){return[[[na ... [详细]
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社区 版权所有