StructureMap Purge Cached Instances
I'm having trouble resetting StructureMap's configuration. This only fails when I run all my tests en mass. A previous test is Injecting an instance of SingleInvoicePresenter, but by the time I get to this test, I need all caching gone. I would think that ResetDefaults() would clear any previously injected objects out, but this test fails on the assert (when run with all the other tests)
StructureMap.ObjectFactory.ResetDefaults();
StructureMap.ObjectFactory.Configure(x => { x.For<SingleInvoicePresenter>().AlwaysUnique(); });
SingleInvoicePresenter P1 = StructureMap.ObjectFactory.GetInstance<SingleInvoicePresenter>();
SingleInvoicePresenter P2 = StructureMap.ObjectFactory.GetInstance<SingleInvoicePresenter>();
Assert.AreNotSame(P1, P2);
Edit - I would think this would work even without the line
StructureMap.ObjectFac开发者_开发问答tory.Configure(x => { x.For<SingleInvoicePresenter>().AlwaysUnique(); });
but it fails with or without it.
StructureMap.ObjectFactory.EjectAllInstancesOf<SingleInvoicePresenter>();
Using the global objectfactory of structuremap should be avoided in your unit tests. Rather in your test setup you would want to create a new container and pass that or an Icontainer reference into your system under test.
精彩评论