I am trying to inject a laughed instance of ISession (NHibernate) into a structural map. Currently, all this is related to the Bootstrap method, but I want to replace the one that is being mocked. I tried EjectAllInstancesOf, but it threw execption.
[TestFixtureSetUp]
public void TestFixtureSetup()
{
Bootstrapper.Bootstrap();
var mockSession = MockRepository.GenerateStub<ISession>();
var mockLoggerFactory = MockRepository.GenerateStub<ILoggerFactory>();
ObjectFactory.EjectAllInstancesOf<ISession>();
ObjectFactory.EjectAllInstancesOf<ILoggerFactory>();
ObjectFactory.Inject<ISession>(mockSession);
ObjectFactory.Inject<ILoggerFactory>(mockLoggerFactory);
}
Error:
System.NullReferenceException: . StructureMap.Pipeline.HttpContextLifecycle.findHttpDictionary() C:\DEV\ \StructureMap\Source\StructureMap\Pipeline\HttpContextLifecycle.cs: 50 StructureMap.Pipeline.HttpContextLifecycle.FindCache() C:\DEV\ \StructureMap\Source\StructureMap\Pipeline\HttpContextLifecycle.cs: 28 StructureMap.Pipeline.HttpContextLifecycle.EjectAll() C:\DEV\ \StructureMap\Source\StructureMap\Pipeline\HttpContextLifecycle.cs: 23 StructureMap.Pipeline.HttpLifecycleBase`2.EjectAll() C:\DEV\ \StructureMap\Source\StructureMap\Pipeline\HttpLifecycleBase.cs: 18 StructureMap.InstanceFactory.EjectAllInstances() C:\DEV\ \StructureMap\Source\StructureMap\InstanceFactory.cs: 127 StructureMap.PipelineGraph.EjectAllInstancesOf() C:\DEV\ \StructureMap\Source\StructureMap\PipelineGraph.cs: 193 StructureMap.Container.EjectAllInstancesOf() c:\dev\opensource\structuremap\Source\StructureMap\Container.cs: 393 StructureMap.ObjectFactory.EjectAllInstancesOf() C:\DEV\ \StructureMap\Source\StructureMap\ObjectFactory.cs: 277