相关疑难解决方法(0)

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

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

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

public class MyService : IServiceContract
{
    IBusinessLogic _businessLogic;
    public ServiceLayer(IBusinessLogic businessLogic)
    {
        _businessLogic = businessLogic;
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

wcf constructor dependency-injection

41
推荐指数
3
解决办法
4万
查看次数

标签 统计

constructor ×1

dependency-injection ×1

wcf ×1