In The bll layer, we use WCF to provide services. At this layer, we only release one service externally. In order to make our code better maintained, we introduce the abstract factory model.
In this case, we will first create three interfaces:
1) iinfo
Inforesult add (Info info );
Inforesult Update (Info info );
Inforesult Delete (INT infoid );
Infolist getinfolist (searchinfo );
Infolist getinfobyid (INT infoid );
2) iinfotype
It is the same as above.
3) iuserinfo
It is the same as above.
Then implement these three interfaces. We also use infobll as an example:
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 = 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)
{
Return infodal. getinfolist (searchinfo );
}
Public infolist getinfobyid (INT infoid)
{
Return infodal. getinfobyid (infoid );
}
}
}
Then we create a factory interface:
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 ();
}
}
Then implement the factory class:
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 ();
}
}
}
To access the factory class, we define a factory offering class:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace infopub. bllservice
{
Public class common
{
Public static bllfactory = new bllfactory ();
}
}
In this way, we can access our factory class. To provide the factory class method for WCF, we add a commondata class, which is similar to our facade:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace infopub. bllservice
{
Public class commondata
{
# Region global variables
Public static iinfo info = Common. bllfactory. createinfo ();
Public static iinfotype infotype = Common. bllfactory. createinfotype ();
Public static iuserinfo userinfo = Common. bllfactory. createuserinfo ();
# Endregion
}
}
Then define our WCF contract:
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 );
[Operationcontract]
Infolist getinfobyid (INT infoid );
[Operationcontract]
Inforesult addinfotype (infotype );
[Operationcontract]
Inforesult updateinfotype (infotype );
[Operationcontract]
Inforesult deleteinfotype (INT infotypeid );
[Operationcontract]
Infotypelist getinfotypelist (searchinfotype );
[Operationcontract]
Infotypelist getinfotypebyid (INT infoid );
[Operationcontract]
Inforesult adduserinfo (userinfo );
[Operationcontract]
Inforesult updateuserinfo (userinfo );
[Operationcontract]
Inforesult deleteuserinfo (INT userinfoid );
[Operationcontract]
Infolist getuserinfolist (searchuserinfo );
[Operationcontract]
Infolist getuserinfobyid (INT userinfoid );
}
}
Its implementation is as follows:
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)
{
Return commondata.info. getinfolist (searchinfo );
}
Public infolist getinfobyid (INT infoid)
{
Return commondata.info. getinfobyid (infoid );
}
Public inforesult addinfotype (infotype)
{
Return commondata. infotype. Add (infotype );
}
Public inforesult updateinfotype (infotype)
{
Return commondata. infotype. Update (infotype );
}
Public inforesult deleteinfotype (INT infotypeid)
{
Return commondata. infotype. Delete (infotypeid );
}
Public infotypelist getinfotypelist (searchinfotype)
{
Return commondata. infotype. getinfotypelist (searchinfotype );
}
Public infotypelist getinfotypebyid (INT infoid)
{
Return commondata. infotype. getinfotypebyid (infoid );
}
Public inforesult adduserinfo (userinfo)
{
Return commondata. userinfo. Add (userinfo );
}
Public inforesult updateuserinfo (userinfo)
{
Return commondata. userinfo. Update (userinfo );
}
Public inforesult deleteuserinfo (INT userinfoid)
{
Return commondata. userinfo. Delete (userinfoid );
}
Public infolist getuserinfolist (searchuserinfo)
{
Return commondata. userinfo. getuserinfolist (searchuserinfo );
}
Public infolist getuserinfobyid (INT userinfoid)
{
Return commondata. userinfo. getuserinfobyid (userinfoid );
}
}
}
The following is the class graph relationship:
It should be noted that I used the class chart generated by EA in reverse order, and then manually modified it.