This project has moved and is read-only. For the latest updates, please go here.

Inject a IOwinContext

Nov 4, 2013 at 1:25 AM
Edited Nov 4, 2013 at 1:36 AM

On an MVC 5 application I am injecting a IOwinContext using StructureMap as follows:
For<IOwinContext>().Transient().Use(() => HttpContext.Current.GetOwinContext());
And I get the following error:

{"No owin.Environment item was found in the context."}

StructureMap Exception Code: 207
Internal exception while creating Instance '945af8da-4216-41a7-9ec2-42d84a22580e' of PluginType Microsoft.Owin.IOwinContext, Microsoft.Owin, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35. Check the inner exception for more details.

I have the Startup class in my MVC 5 application ...

How can I set the owin.Environment?

Thank You, Miguel
Nov 4, 2013 at 6:15 PM
Pasting the original error (eaten by the UI):
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 
I won't claim to know anything about StructureMap, but it sounds like it's trying to call the IOwinContext(IDictionary<string, object>) constructor, but can't find a registered instance of IDictionary in your container to pass in. Try adding one?