目录
业务层实现主要业务逻辑接口IBLL(Interface business logic layer )、BLL(接口实现层)以及DAL(数据交互层)。
新建Business文件夹,分别添加Business、IBusiness、Service工程,每个下可以添加具体类。
为了方便管理一般三个工程类前缀名相同,可以是某人、某个工程的名称,后缀分别为BLL,IBLL,DAL。
以NorthWind为例:
业务层处于接口与底层数据库操作之间。
编写一个测试demo,实现接口访问业务层访问数据层。
1、IBusiness
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace IBussiness
{
public interface NorthWindIBLL
{
string test(string str);
}
}
2、Service
添加DataAccess.DataBase.SqlServer,Utilities;
using System.Data;
using DataAccess.DataBase.SqlServer;
using Utilities;
namespace DAL
{
public class NorthWindDAL
{
public string test(string str)
{
string opSql = "select*from Products where SupplierID>10";
DataTable da = SqlServerHelper.ExectuteDataTable(SqlServerHelper.connString, CommandType.Text, opSql, null);
//string strJson = ConvertToJson.ToJSON(da);
string strJson = ConvertJson.ToJson(da);
return strJson;
}
}
}
3、Business
业务是实现层,添加DataAccess.DataBase.SqlServer;
类继承接口
using System;
using IBussiness;
using DAL;
namespace Bussiness
{
public class NorthWindBLL:NorthWindIBLL
{
private readonly NorthWindDAL dal = new NorthWindDAL();
//test
public string test(string str)
{
try
{
string strJson = dal.test(str);
return "{\"erron\":0,\"errmsg\":\"成功!\",\"data\":" + strJson + "}";
}
catch (Exception e)
{
return e.Message.ToString();
}
}
}
}
4、webservice接口
添加Bussiness、IBussiness引用。
[WebMethod(Description = "接口-业务-数据")]
//test
public string test(string str)
{
string result = string.Empty;
NorthWindIBLL bll = new NorthWindBLL();
result = bll.test(str);
return result;
}
运行结果: