Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional stream prefix per aggregate #87

Merged
merged 4 commits into from Oct 2, 2017

Conversation

slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented Oct 2, 2017

Add support to command router to allow further specification of an aggregate identity and additionally an identity prefix.

  1. Allow the aggregate identity prefix to be specified during command registration:

    defmodule BankRouter do
      use Commanded.Commands.Router
    
      dispatch [OpenAccount,DepositMoney,WithdrawMoney] 
        to: BankAccount, 
        identity: :account_number,
        identity_prefix: "bank-account-"
    end
  2. Allow a function to be used as the identity option; you construct the identity as required from the command being dispatched:

    defmodule BankRouter do
      use Commanded.Commands.Router
    
      dispatch [RegisterUser] 
        to: User, 
        identity: fn %{uuid: uuid} -> "user-#{uuid}" end
    
      dispatch [OpenAccount,DepositMoney,WithdrawMoney] 
        to: BankAccount, 
        identity: &BankRouter.account_identity/1
    
      def account_identity(%{account_number: account_number}), do: "bank-account-#{account_number}"
    end
  3. Allow an aggregate identity to be specified for all its commands, providing an optional prefix:

    defmodule BankRouter do
      use Commanded.Commands.Router
    
      identify BankAccount, 
        by: :account_number, 
        prefix: "bank-account-"
    
      dispatch [OpenAccount,DepositMoney,WithdrawMoney] to: BankAccount
    end

Closes #77.

@slashdotdash slashdotdash merged commit 909312e into master Oct 2, 2017
@slashdotdash slashdotdash deleted the feature/aggregate-prefix branch October 2, 2017 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Additional stream prefix per aggregate
1 participant