Cached instances of StructureMap

I'm having trouble resetting StructureMap. This only happens when I run all my tests in bulk. The previous test is an Injecting instance of SingleInvoicePresenter, but by the time I get to this test, I need all the caching to be gone. I would have thought that ResetDefaults () would clear all previously nested objects, but this test would not work on approval (when run with all 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 that this would work even without a string

StructureMap.ObjectFactory.Configure(x => { x.For<SingleInvoicePresenter>().AlwaysUnique(); });

but he does not work with or without him.

+3
source share
2 answers
StructureMap.ObjectFactory.EjectAllInstancesOf<SingleInvoicePresenter>();
+1
source

objectfactory . , Icontainer .

+1

Source: https://habr.com/ru/post/1762886/


All Articles