gpt4 book ai didi

wcf - WCF 服务可以有构造函数吗?

转载 作者:行者123 更新时间:2023-12-02 13:11:52 25 4
gpt4 key购买 nike

当我在我的解决方案中新建一个 WCF 服务时,我可以执行以下操作,让构造函数传入参数吗?如果是,运行时如何、何时、何地填充我所需的 IBusinessLogic 对象?

[ServiceContract]
public interface IServiceContract
{
[OperationContract]
...
}

public class MyService : IServiceContract
{
IBusinessLogic _businessLogic;
public ServiceLayer(IBusinessLogic businessLogic)
{
_businessLogic = businessLogic;
}
...
}

最佳答案

开箱即用的 WCF 将仅使用默认构造函数,不能使用参数化构造函数。您必须做一些额外的工作才能使 WCF 调用参数化构造函数。

你可以试试这个:

How do I pass values to the constructor on my wcf service?

关于wcf - WCF 服务可以有构造函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/381831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com