6

我目前正在使用 OWIN 将 WebApi 1 移动到 WebApi 2 项目。

在这段代码中,GlobalConfiguration 在 System.Web.Http.WebHost 中。

public class HandlerErrorFilterAttribute : ExceptionFilterAttribute
{
    public override void OnException(HttpActionExecutedContext context)
    {
        var logFactory = GlobalConfiguration.Configuration.DependencyResolver
                            .GetService(typeof(ILoggerFactory)) as ILoggerFactory;
        ...
    }
}

我认为这与 Owin 不兼容,但我找不到如何重写它,因此我可以访问依赖解析器。

4

1 回答 1

4

我在这里对您的问题并不完全清楚...但是 GlobalConfiguration 与 Owin 中间件兼容...还有一个称为System.Web.Http.OwinWeb API Owin Adpater 中间件的东西...如果您使用此适配器,则不能使用 GlobalConfiguration 。 ..实际上,这也是在 Owin Selfhost 场景中使用的同一个适配器......

如果您不使用此适配器而仅使用其他 Owin 中间件以及System.Web.Http.WebHost,那么您上面的代码应该可以正常工作...您看到什么不同了吗?

于 2013-11-14T17:40:44.823 回答