2011-08-17 96 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)是解決此問題的第一步。