@@ -147,6 +147,7 @@ defmodule Commanded.Aggregates.Aggregate do
147147 defstruct [
148148 :application ,
149149 :aggregate_module ,
150+ :state_module ,
150151 :aggregate_uuid ,
151152 :aggregate_state ,
152153 :snapshotting ,
@@ -160,6 +161,7 @@ defmodule Commanded.Aggregates.Aggregate do
160161
161162 aggregate_module = Keyword . fetch! ( aggregate_opts , :aggregate_module )
162163 aggregate_uuid = Keyword . fetch! ( aggregate_opts , :aggregate_uuid )
164+ state_module = Keyword . get ( aggregate_opts , :state_module ) || aggregate_module
163165
164166 unless is_atom ( aggregate_module ) ,
165167 do: raise ( ArgumentError , message: "aggregate module must be an atom" )
@@ -174,6 +176,7 @@ defmodule Commanded.Aggregates.Aggregate do
174176 state = % Aggregate {
175177 application: application ,
176178 aggregate_module: aggregate_module ,
179+ state_module: state_module ,
177180 aggregate_uuid: aggregate_uuid ,
178181 snapshotting: Snapshotting . new ( application , aggregate_uuid , snapshot_options )
179182 }
@@ -230,7 +233,16 @@ defmodule Commanded.Aggregates.Aggregate do
230233 end
231234
232235 @ doc false
233- def aggregate_state ( application , aggregate_module , aggregate_uuid , timeout \\ 5_000 ) do
236+ def aggregate_state ( application , aggregate_module , aggregate_uuid , timeout_or_opts \\ 5_000 )
237+
238+ def aggregate_state ( application , aggregate_module , aggregate_uuid , timeout )
239+ when is_integer ( timeout ) or timeout == :infinity do
240+ aggregate_state ( application , aggregate_module , aggregate_uuid , timeout: timeout )
241+ end
242+
243+ def aggregate_state ( application , aggregate_module , aggregate_uuid , opts ) when is_list ( opts ) do
244+ timeout = Keyword . get ( opts , :timeout , 5_000 )
245+ state_module = Keyword . get ( opts , :state_module , aggregate_module )
234246 name = via_name ( application , aggregate_module , aggregate_uuid )
235247
236248 try do
@@ -249,6 +261,7 @@ defmodule Commanded.Aggregates.Aggregate do
249261 % Aggregate {
250262 application: application ,
251263 aggregate_module: aggregate_module ,
264+ state_module: state_module ,
252265 aggregate_uuid: aggregate_uuid ,
253266 snapshotting: Snapshotting . new ( application , aggregate_uuid , snapshot_options )
254267 }
0 commit comments