asp.net web api - Ninject OWIN extensions break CreatePerOwinContext for Web API -


In an attempt to use Nig with a new web API 2 project, which uses ASP.NET identification I have some weird behavior I can not pass the callback to CreatePerOwinContext () to fire for requests of web API controllers They work fine for MVC controllers.

Steps to recreate:

  1. File - & gt; New vs 2013 ASP.NET Web Application
  2. MVC & amp; WebAPI
  3. Select individual under authentication
  4. Ninject, ninject.Web.Common.OwinHost, Ninject.Web.WebApi.OwinHost & amp; Add Nougat package for
  5. To configure ninject for your Owin enabled app
  6. Place a breakpop in your ApplicationUserManager.Create () and then F5 debug
  7. Your Home Controller Work OK - Breakpoint Hit. Request an intelligence for the API controller - say, API / account / register and callback are sometimes not called

    I'm not a ninja above so I am unsure If it's doing something wrong or a bug in the Ninject OWIN extension, I'm leaning except OwinContext and using only Ninject perHttpRequest scoping, but I am unsure if ASP.NET detection system will break. I have heard that OwinContext.Get () can be an internal call, which does not hold things in terms of o wine, it will be broken.

    Many appreciate the thoughts of someone.

    I ended up using Ninject for all life-time management. Obviously .CreatePerOwinContext () is one that does not require you to use full-blown DI equipment.

    The only thing I have seen is that Cookie based Aeth, ASP.NET identity will look for its UserManager in OwinContext. I am using tokens based athits, but I have seen some people moving forward and bring stuff to usermener in OwinContext.

    My Ninja Binding:

      Private static lazy to read only & lt; IKernel & gt; _lazyKernel = new lazy & lt; I kernel & gt; (CreateKernel); // Access to Singleton Kernel via this Property Public Stable IKernel Kernel (get {return _lazyKernel.Value;}} Private Void Configure Enge {app.UseNinjectMiddleware ((= ===> Kernel); Kernel. Bind & LT; IAppBuilder & gt; () ToConstant.} Private Static Empty Register Services (I Colonel Kernel) {kernel.Bind  (). ToSelf () .InRequestScope (). WithConstructorArgument ( "ConnectionString", "MyConnectionString"); Kernel.Bind & lt; IUserStore & lt; MyApplicationUser, int & gt; & gt; (). MyUserStore & gt; (). InRequestScope (); Colonel.bund & lt ; IRoleStore & lt; MyRole, int & gt; & gt; & Lt; MyRoleStore & gt; () .InRequestScope (); kernel.Bind & lt; MyUserManager & gt; () ToSelf () InRequestScope () .. kernel.Bind & lt; ISecureDataFormat & lt; AuthenticationTicket & gt; & gt; ;.); SecureDataFormat & lt; AuthenticationTicket & gt; & gt; (); kernel.Bind & lt; IDataSerializer & lt; AuthenticationTicket & gt; & gt ;.) & lt; TicketSerializer & gt; (); Col.bund & lt; IDataProtector & gt; (). ToMethod (x = & gt; x.Kernel.Get & lt; IAppBuilder & gt; (.) GetDataProtectionProvider (). Create ("ASP.NET detection")); Kernel.Bind & LT; ITextEncoder & gt; () & Lt; Base64UrlTextEncoder & gt; (); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -