Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GlobalConfiguration in System.Web.Http.WebHost compatible with Owin?

I'm currently moving a WebApi 1 to a WebApi 2 project with OWIN.

In this piece of code GlobalConfiguration is in System.Web.Http.WebHost.

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

I think this is not Owin compatible, but I can't find how to rewrite this so I can access the dependency resolver.

like image 641
JuChom Avatar asked Nov 14 '13 15:11

JuChom


1 Answers

I am not entirely clear about your question here...but GlobalConfiguration is comaptible with Owin middleware...There is also something called System.Web.Http.Owin which is an Web API Owin Adpater middleware...if you use this adapter then GlobalConfiguration must not be used...actually this is the same adapter which is used in case of Owin Selfhost scenario too...

if you are NOT using this adapter and just using other Owin middleware along with System.Web.Http.WebHost, then your above code should work just fine...are you seeing anything different?

like image 146
Kiran Avatar answered Nov 22 '22 10:11

Kiran