【发布时间】:2011-08-18 16:48:58
【问题描述】:
我一直致力于 .net 4.0 webapi restful 服务项目。在该项目中,我们希望动态注入 WebOberationContext.Current 对象之一。有没有办法使用 Autofac 来实现这一点。我google了很多,但还没有找到解决方案。目前我正在使用以下代码:
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;
}
}
我想知道我们是否可以使用 autofac 自动注入它,而不是将 WebOperationContext 设置为属性。
非常感谢任何信息。
谢谢
【问题讨论】:
-
只是好奇 - 为什么需要注入上下文?你是在嘲笑它进行测试还是什么?