WCF服务可以有构造函数吗? [英] Can WCF Service have constructors?
本文介绍了WCF服务可以有构造函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在我的解决方案中新的WCF服务,我可以做以下,有一个参数的构造函数传入?如果是,运行时如何,何时和在哪里将填充我需要的IBusinessLogic对象?
When I new a WCF service in my solution, can I do the following, have a constructor with parameter to pass in? If yes, how, when and where does the runtime fill in my required IBusinessLogic object?
[ServiceContract]
public interface IServiceContract
{
[OperationContract]
...
}
public class MyService : IServiceContract
{
IBusinessLogic _businessLogic;
public ServiceLayer(IBusinessLogic businessLogic)
{
_businessLogic = businessLogic;
}
...
}
推荐答案
开箱即用的WCF将只使用默认构造函数,你不能使用参数化构造函数。你必须做一些额外的工作,使WCF调用参数化构造函数。
Out of the box WCF will only use the default constructor, you can't use parameterised constructors. You have to do a bit of extra work to make WCF call parameterised constructors.
你可以尝试:
这篇关于WCF服务可以有构造函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文