简体   繁体   English

WCF RESTful 服务注入 WebOperationContext 与 Autofac

[英]WCF restful service injecting WebOperationContext with Autofac

I have been working on .net 4.0 webapi restful service project.我一直在从事 .net 4.0 webapi restful 服务项目。 In that project in one the of object we would like to inject WebOberationContext.Current dynamically.在 object 之一的那个项目中,我们想动态注入 WebOberationContext.Current。 Is there any way to achieve this using Autofac.有没有办法使用 Autofac 来实现这一点。 I googled a lot, but haven't found a solution, yet.我google了很多,但还没有找到解决方案。 For the time being i am using the following code:目前我正在使用以下代码:

public class SomeObject : ISomeObject
{
     private readonly ISomeService _someService;
     public SomeObject(ISomeService someService)
     {
        _someService = someService;
     }

     public WebOperationContext Context { get; set; }

     public void SomeOperation()
     {
          var incomeRequtests = Context.Current.IncomingRequests;
     }
}

Rather than set WebOperationContext as property, i want to find out, if we can auto inject it using autofac.我不想将 WebOperationContext 设置为属性,而是想知道我们是否可以使用 autofac 自动注入它。

Any info is greatly appreciated.非常感谢任何信息。

Thanks谢谢

No, you can't change the context.不,你不能改变上下文。 This is one often-complained problems with WCF, the lack of "unit-testability" (especially things such as the WebOperationContext or the OperationContext).这是 WCF 的一个经常被抱怨的问题,缺乏“单元可测试性”(尤其是诸如 WebOperationContext 或 OperationContext 之类的东西)。 The new WCF Web APIs (from http://wcf.codeplex.com ) are a good first step towards fixing this problem. The new WCF Web APIs (from http://wcf.codeplex.com ) are a good first step towards fixing this problem.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM