Skip to content
CCPEDIAby Unity Nodes
App Development

Make fields nested inside a data type from template parameters available for autowiring/autobinding in choice scope

5 posts508 views7 likesLast activity Aug 2021

  1. meetOP
    template LoanApproval
      with
        loanApplication: LoanApplication
        loanTerms: LoanTerms
      where 
        signatory loanApplication.bank
        controller loanApplication.customer can 
          SignAgreement: ContractId LoanAgreement
            do create LoanAgreement with ..
    

    Is it possible to use the LoanApplication {..} syntax to make the fields inside loanApplication directly available in the choice scope for “autowiring” at do create SignHirePurchaseAgreement with .. ?

  2. Leonid_Rozenberg 4

    In the choice body

    let LoanApplication { .. } = loanApplication
    
  3. meet

    Thank you!

  4. Leonid_Rozenberg 1

    Just remember that with great power comes great responsibility.

    There’s a little devil (or is it an angel) that nags at me when I use this syntax as it can do so much work that I might not notice when it does too much.

  5. Stephen 2

    TBQH it is less devilish than .. in record-creation; introducing a bunch of bindings seems much less scary to me than automatically using whatever bindings are laying around. Certainly one of the unstated reasons I posted about using records more was to encourage a Daml style that wouldn’t lean so heavily on .. record creation.

    Then again I come from the “DI is useless, just pass arguments to a function” school of thought.

    @meet On a more serious note, if the same set of fields happens to be used in several places, it may be clearer to factor that set of fields to a record, and then pass it explicitly. Of course that totally depends on the other code details not seen here.