我有一个SessionWebAppService类,它在构造函数中使用HttpContext和HttpContextBase类:
public class SessionWebAppService : WebAppServiceBase, ISessionWebAppService
{
public SessionWebAppService(HttpContext httpContext)
: this(new ConcertDb(), new WebFormContext(httpContext))
{
}
public SessionWebAppService(HttpContextBase httpContext)
: this(new ConcertDb(), new MvcContext(httpContext))
{
}
public SessionWebAppService(IConcertDb concertDb, IConcertHttpContext httpContext)
: base(concertDb, httpContext)
{
}
我应该使用Autofac在Global.asax.cs文件中的ASP.NET应用程序中注册HttpContext和HttpContextBase类,但我不知道该怎么做。
答案 0 :(得分:0)
如果您正在使用MVC,则可以注册Autofac.Integration.Mvc.AutofacWebTypesModule
以获取已注册的网络抽象(例如HttpContextBase
)。
如果你没有使用MVC,你可以look at the source for AutofacWebTypesModule查看它是如何完成的。