Skip to content

Orleans - BankAccount sample should use AtmGrain for transaction coordination #7093

@freireomarcos

Description

@freireomarcos

Orleans - BankAccount sample should use AtmGrain for transaction coordination

The Orleans BankAccount sample (located at orleans/BankAccount/) includes an AtmGrain implementation but doesn't use it in the client code. Instead, the client directly coordinates transactions using ITransactionClient.RunTransaction().

Issues with this approach:

  • Client is responsible for orchestrating business logic
  • Confuses learners about when to use orchestrator grains vs client-side coordination
  • The AtmGrain class exists but is never used, making its purpose unclear

Preferred Modern Approach

var atm = client.GetGrain<IAtmGrain>(0); await atm.Transfer(fromAccount, toAccount, transferAmount);

Benefits:

  • Separation of concerns: Business logic stays in grains, not in client code
  • Orleans best practices: Demonstrates proper use of orchestrator/coordinator grains
  • Simpler client code: One method call instead of explicit transaction management
  • Utilizes existing code: Makes use of the already-implemented AtmGrain

Proposed Changes

Location: orleans/BankAccount/BankClient/Program.cs

  • Remove ITransactionClient dependency
  • Add IAtmGrain usage
  • Replace transaction coordination block with atm.Transfer() call

Optional: Add a comment explaining the pattern


Issue metadata

  • Issue type: sample-update

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions