1
votes

We are using StructureMap to cache a a class by InstanceScope.HttpContext. When unit testing a controller that depends on this type, null reference exceptions are thrown from within StructureMap that seem to indicate that it is trying to access the static current HttpContext (and not the MVC wrappers).

How could we fully configure HttpContext.Current (having decompliled structuremap it seems the error comes from here) to have a valid context that would work correctly with structuremap?

2
You're using StructureMap in your unit tests as well? Why? - Dismissile

2 Answers

2
votes

This is a known bug

Just implement the fix and compile.

0
votes

Have you tried / You could use:

containter.For<ICupCakeService>().HybridHttpOrThreadLocalScoped().Use<MyCupCakeService>();

... Which will use HttpContext storage if it exists, otherwise use ThreadLocal storage.

More: StructureMap - Scoping and Lifecycle Management