Make fields nested inside a data type from template parameters available for autowiring/autobinding in choice scope
- 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 insideloanApplicationdirectly available in the choice scope for “autowiring” atdo create SignHirePurchaseAgreement with ..? - Leonid_Rozenberg 4
In the choice body
let LoanApplication { .. } = loanApplication - meet
Thank you!
- 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.
- 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.