remogloor / Ninject.Web.WebApi

Adds support for web API to Ninject
Other
16 stars 48 forks source link

Incorrect implementation for WebApi with Owin (do not use this extension for the time being!) #16

Open MoonStorm opened 8 years ago

MoonStorm commented 8 years ago

The extension has severe bugs when it comes to dealing with Owin. I would strongly recommend everyone to stay away from this until these bugs have been fixed.

The OwinNinjectDependencyResolver creates a named scope but it never uses it for resolving via HttpConfiguration.DependencyResolver. It's not proxying the calls to the proper resolution root, and it fails silently in OwinWebApiRequestScopeProvider with an UnknownScopeException, returning a NULL request scope. InRequestScope instances resolved like this will behave as transient and will not be cleaned up!

The implementation is also incompatible with Owin middleware pipeline. The Ninject.Web.Common.OwinHost creates a scope for this purpose inside OwinBootstrapper, however this extension completely ignores it. When attempting to resolve services inside middlewares, it behaves exactly the same as described above, failing silently and creating transient instances instead.

In a nutshell, the extension fails to properly cope with an Owin request scope. Using it can have severe consequences leading to unexpected situations which are very hard to detect and solve. I can't stress enough. This extension is NOT ready for prime time!

MoonStorm commented 8 years ago

Also reported in the ninject repo, I'm not sure which one is being used. I see more activity here for some reason.