简体   繁体   中英

How can I register IAuthenticationManager in Global.asax with StructureMap

I want register IAuthenticationManager in Application_Start() with this code:

//
 x.For<IAuthenticationManager>().Use(HttpContext.Current.GetOwinContext().Authentication);  

When I run my mvc5 project I get this error

No owin.Environment item was found in the context

I believe the overload for Use that you are invoking here is attempting to resolve immediately and there is no current HttpContext during App Start. Try using the overload for Use that has a Func parameter to be used for construction.

x.For<IAuthenticationManager>().Use(ctx => HttpContext.Current.GetOwinContext().Authentication);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM