关于自托管WCF服务与其他业务类之间的交互,我有一个相当简单的设计问题。
以下是WCF服务合同:
/// <summary>
/// Represent requests on hardware components made by a client to the controler service
/// </summary>
[ServiceContract(CallbackContract = typeof(IHardwareServiceCallback))]
public interface IHardwareService
{
[OperationContract(IsOneWay = true)]
void OpenLeftDrawer();
[OperationContract(IsOneWay = true)]
void OpenRightDrawer();
}
服务实施
public class HardwareService : IHardwareService
{
public void OpenLeftDrawer()
{
}
public void OpenRightDrawer()
{
}
}
一个目的是处理有关服务器上客户端调用的业务逻辑的类
class DrawerRequestManager
{
// Server side Business logic to handle OpenDrawer requests from client
}
主机方案
Uri adrbase = new Uri(srvConfig.Address);
var host = new ServiceHost(typeof(HardwareService), adrbase);
host.AddServiceEndpoint(typeof(IHardwareService), srvConfig.Binding, srvConfig.Address);
host.Open();
由于这是管理服务实例生命周期的主机,因此正确的方法处理服务实例和业务逻辑类之间的链接(例如DrawerRequestManager
)。
我使用的是IOC容器,但我也对不使用IOC容器时的响应感兴趣。
提前致谢!