How to get IAuthenticationManager implementation displayed in StructureMap
I am struggling to use StructureMap and Microsoft AspNet Identity as I am unable to figure out how to implement the IAuthenticationManager implementation. I'm trying to map this explicitly to the DefaultRegistry in the example below.
public class DefaultRegistry : Registry {
public DefaultRegistry() {
Scan(
scan => {
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);
}
}
The main problem is that HttpContext.Current is always null, but I'm not even sure if this will work, even if it's not null. I'm a big newbie with StructureMap and with AspNet Identity, so feel free to call me about something stupid I'm doing here. Thank you for your help!
source to share
This is really not a StructureMap problem. HttpContext.Current will only be available inside an HTTP request in ASP.Net. If you want to use HttpContext in a StructureMap, I would suggest either making sure you check for null gracefully, or try to switch to using the HttpContextWrapper / HttpContextBase abstraction so you can run this code outside of ASP.Net in your tests.
source to share