I'm trying to write an end-to-end 'unit' test of my client server system.
In my test, I create an instance of the server and one of the client.
I then invoke the client which calls a WCF service on the server. It works well.
However -- I can see that at least in one case (StructureVault) the exact same instance is reused in both application object hierarchies, which is undesireable, not least because both applications register cache items in the object.
Furthermore, lock(this){} wrappings on the client cause deadlock when server tries to access the same during WCF call (which alerted me to the problem).
I've found discussions here on SO and tried the construction below. It did not solve my issue.
I can see that the problematic object is created twice as expected, but the lastly created object is used in both hierarchies.
The GetTestRoot... calls in code below calls ObjectFactory.Initialize to wire up before returning the root of hierarchy. The StructureVault object should be Singleton within each hierarchy.
For<IStructureVault>()
.Singleton().Use<StructureVault>();
Any suggestions on what to do/try?!
Code:
var testRootCalculationServer =
DbIntegrationTestHelper
.GetTestRootCalculationServer("2",
UserNameConst.SystemName,
Rap1DEnvironment.LocalDevEnv);
StructureMap.ObjectFactory.EjectAllInstancesOf<IStructureVault>();
StructureMap.ObjectFactory.Initialize(x=>{});
var testRootRap1DGui1 =
DbIntegrationTestHelper
.GetTestRootRap1DGui("1",
UserNameConst.SystemName,
Rap1DEnvironment.LocalDevEnv, false);