[置顶]信息发布系统 Jquery+MVC架构开发(6)BLL层提供WCF 服务

 

BLL层我们用wcf 来提供服务,这一层我们只对外只发布一个服务,为了使我们的代码可维护更好,我们引入抽象工厂模式。

这样的话我们首先也创建三个接口:

1)  IInfo

InfoResult Add(Info info);
InfoResult Update(Info info);
InfoResult Delete(int infoId);
InfoList GetInfoList(SearchInfo searchInfo);
InfoList GetInfoById(int infoId);

2)  IInfoType
跟上面相同,不再赘述。

3)  IUserInfo
跟上面相同,不再赘述。

然后实现这三个接口,我们也用infoBll为例如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using InfoPub.DAL;

using InfoPub.Modal;

 

namespace InfoPub.BLLService

{

    public class InfoBLL:IInfo

    {

        private InfoDal infoDal=new InfoDal();

        public InfoResult Add(Info model)

        {

            return infoDal.Add(model);

        }

         public InfoResult Update(Info model)

         {

             return infoDal.Update(model);

         }

 

        public InfoResult Delete(int infoId)

        {

            return infoDal.Delete(infoId);

        }

        public InfoList GetInfoList(SearchInfo searchInfo)

        {

            return infoDal.GetInfoList(searchInfo);

        }

 

        public InfoList GetInfoById(int infoId)

        {

            return infoDal.GetInfoById(infoId);

        }

    }

}

 

然后我们创建一个工厂接口:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace InfoPub.BLLService.Interface

{

    public interface INBllFactory

    {

        IInfo CreateInfo();

        IInfoType CreateInfoType();

        IUserInfo CreateUserInfo();

    }

}

然后实现工厂类:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using InfoPub.BLLService.Interface;

 

namespace InfoPub.BLLService

{

    public class BllFactory : INBllFactory

    {

        public IInfo CreateInfo()

        {

            return new InfoBLL();

        }

        public IInfoType CreateInfoType()

        {

            return new InfoTypeBLL();

        }

        public IUserInfo CreateUserInfo()

        {

            return new UserInfoBLL();

        }

    }

}

 

为了访问工厂类我们定义一个工厂提供类:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace InfoPub.BLLService

{

    public class Common

    {

        public static BllFactory bllFactory=new BllFactory();

    }

 

}

 

这样我们就可以访问我们的工厂类了,为了对wcf 提供工厂类的方法,我们加入一个CommonData类,它就类似我们的门面:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace InfoPub.BLLService

{

    public class CommonData

    {

        #region 全局变量

        public static IInfo info = Common.bllFactory.CreateInfo();

        public static IInfoType infoType = Common.bllFactory.CreateInfoType();

        public static IUserInfo userInfo = Common.bllFactory.CreateUserInfo();

        #endregion

 

    }

}

然后定义我们的wcf 契约:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

using InfoPub.Modal;

 

namespace InfoPub.BLLService

{

    [ServiceContract]

    public interface IInfoPubService

    {

        [OperationContract]

        InfoResult AddInfo(Info info);

        [OperationContract]

        InfoResult UpdateInfo(Info info);

        [OperationContract]

        InfoResult DeleteInfo(int infoId);

        [OperationContract]

        InfoList GetInfoList(SearchInfo searchInfo);

        [OperationContract]

        InfoList GetInfoById(int infoId);

        [OperationContract]

        InfoResult AddInfoType(InfoType infoType);

        [OperationContract]

        InfoResult UpdateInfoType(InfoType infoType);

        [OperationContract]

        InfoResult DeleteInfoType(int infoTypeId);

        [OperationContract]

        InfoTypeList GetInfoTypeList(SearchInfoType searchInfoType);

        [OperationContract]

        InfoTypeList GetInfoTypeById(int infoId);

        [OperationContract]

        InfoResult AddUserInfo(UserInfo userInfo);

        [OperationContract]

        InfoResult UpdateUserInfo(UserInfo userInfo);

        [OperationContract]

        InfoResult DeleteUserInfo(int userinfoId);

        [OperationContract]

        InfoList GetUserInfoList(SearchUserInfo searchUserInfo);

        [OperationContract]

        InfoList GetUserInfoById(int userInfoId);

 

    }

}

 

它的实现如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

using InfoPub.Modal;

 

namespace InfoPub.BLLService

{

    public class InfoPubService : IInfoPubService

    {

        public InfoResult AddInfo(Info info)

        {

            return CommonData.info.Add(info);

        }

 

        public InfoResult UpdateInfo(Info info)

        {

            return CommonData.info.Update(info);

        }

 

        public InfoResult DeleteInfo(int infoId)

        {

            return CommonData.info.Delete(infoId);

        }

 

        public InfoList GetInfoList(SearchInfo searchInfo)

        {

            return CommonData.info.GetInfoList(searchInfo);

        }

 

        public InfoList GetInfoById(int infoId)

        {

            return CommonData.info.GetInfoById(infoId);

        }

 

        public InfoResult AddInfoType(InfoType infoType)

        {

            return CommonData.infoType.Add(infoType);

        }

 

        public InfoResult UpdateInfoType(InfoType infoType)

        {

            return CommonData.infoType.Update(infoType);

        }

 

        public InfoResult DeleteInfoType(int infoTypeId)

        {

            return CommonData.infoType.Delete(infoTypeId);

        }

 

        public InfoTypeList GetInfoTypeList(SearchInfoType searchInfoType)

        {

            return CommonData.infoType.GetInfoTypeList(searchInfoType);

        }

 

        public InfoTypeList GetInfoTypeById(int infoId)

        {

            return CommonData.infoType.GetInfoTypeById(infoId);

        }

 

        public InfoResult AddUserInfo(UserInfo userInfo)

        {

            return CommonData.userInfo.Add(userInfo);

        }

 

        public InfoResult UpdateUserInfo(UserInfo userInfo)

        {

            return CommonData.userInfo.Update(userInfo);

        }

 

        public InfoResult DeleteUserInfo(int userinfoId)

        {

            return CommonData.userInfo.Delete(userinfoId);

        }

 

        public InfoList GetUserInfoList(SearchUserInfo searchUserInfo)

        {

            return CommonData.userInfo.GetUserInfoList(searchUserInfo);

        }

 

        public InfoList GetUserInfoById(int userInfoId)

        {

            return CommonData.userInfo.GetUserInfoById(userInfoId);

        }

    }

}

 

 

下面是我们的类图关系:

需要说明的是我这个是用ea逆向生成的类图,然后手工修改了一下。

[置顶]信息发布系统 Jquery+MVC架构开发(6)BLL层提供WCF 服务_第1张图片

 

你可能感兴趣的:(jquery)