2011-08-17 99 views
0

我一直在处理.net 4.0 webapi宁静服务项目。在该项目中,我们希望动态注入WebOberationContext.Current。有没有什么办法可以使用Autofac来达到这个目的。我GOOGLE了很多,但还没有找到解决方案。就目前我使用下面的代码:WCF宁静服务注入WebOperationContext与Autofac

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; 
    } 
} 

而不是设置WebOperationContext财产,我想了解,如果我们可以用autofac自动注入它。

任何信息非常感谢。

谢谢

+0

只是好奇 - 为什么你需要注入上下文?你是在嘲笑它进行测试吗? –

回答

0

不,你不能改变上下文。这是WCF常常抱怨的问题,缺乏“单元测试性”(特别是诸如WebOperationContext或OperationContext等)。新的WCF Web API(来自http://wcf.codeplex.com)是解决此问题的第一步。