【问题标题】:Is GlobalConfiguration in System.Web.Http.WebHost compatible with Owin?System.Web.Http.WebHost 中的 GlobalConfiguration 是否与 Owin 兼容?
【发布时间】:2013-11-15 06:34:43
【问题描述】:

我目前正在使用 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 不兼容,但我找不到如何重写它以便访问依赖解析器。

【问题讨论】:

    标签: asp.net-web-api owin katana


    【解决方案1】:

    我在这里对您的问题并不完全清楚...但是 GlobalConfiguration 与 Owin 中间件兼容...还有一个叫做 System.Web.Http.Owin 的东西,它是一个 Web API Owin Adpater 中间件...如果您使用这个适配器然后不得使用 GlobalConfiguration...实际上这与 Owin Selfhost 场景中使用的适配器相同...

    如果您没有使用此适配器,而仅使用其他 Owin 中间件和 System.Web.Http.WebHost,那么您的上述代码应该可以正常工作...您发现有什么不同吗?

    【讨论】:

    • 我在新的WebApi项目中使用的是System.Web.Http.Owin,所以GlobalConfiguration是要避免的!这个中间件有等效的东西吗?
    • 我也有同样的问题。 owin 有没有等价物?你发现了吗?
    猜你喜欢
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 2011-05-23
    • 2011-10-22
    • 2017-02-12
    • 1970-01-01
    相关资源
    最近更新 更多