Hi Rickard,

I think it's a problem in our current Qi4j-DCI execution model that we can't 
instantiate the same Context twice without getting unexpected results.

In the payBills creditor loop we moved the TransferMoneyContext instantiation 
outside the creditor loop, which I think is not entirely intuitive, but can of 
course work in this case since instantiation and enactment is in the same place 
and therefore easily reviewable (according to DCI requirements). 

The real problem comes when client code needs to enact the same Use case in 
different independent parts of the client code. We _could_ pass a Context 
instance around but I think this is a clumsy and less reviewable solution (even 
with the rebind).

If you copy this test into the TransferMoneyTest (v11), I think it should be 
possible to do:

   @Test
   public void transferTwice() throws Exception
   {
      UnitOfWork uow = assembler.unitOfWorkFactory().newUnitOfWork( newUsecase( 
"Transfer twice" ) );

      try
      {
         Bank bank = uow.get( Bank.class, BANK );
         Balance checkingAccount = uow.get( SavingsAccountEntity.class, 
SAVINGS_ACCOUNT_ID );
         Balance bakerAccount = uow.get( CreditorRolemap.class, CREDITOR_ID1 );
         Balance butcherAccount = uow.get( CreditorRolemap.class, CREDITOR_ID2 
);

         new TransferMoneyContext( bank, checkingAccount, bakerAccount 
).transfer( 50 );

         // Another enactment in a completely different place in client code 
should be possible
         new TransferMoneyContext( bank, checkingAccount, butcherAccount 
).transfer( 90 );

         uow.complete();
      }
      catch (Exception e)
      {
         uow.discard();
         throw e;
      }
   }

Output shows that bakerAccount has wrongly been paid twice (and butcherAccount 
never come into play):

BakerAccount:90
ButcherAccount:-90

Is there a way to enforce subsequent Context instantiations to get injected 
*again* without getting old Method-/Mixins-instances from the instancePools? Or 
do you see some other workaround?

I think it would be great if client code could freely instantiate and enact any 
Context at any point.

Cheers,
Marc
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to