Plans to deprecate apply_*
handlers in AggregateRoot?
#1345
-
Hello all, happy Thursday and happy summer to those of you in the northern hemisphere! The documentation on Event Sourcing with AggregateRoot talks about the two ways of defining handler methods and notes (only by dropping the word “(deprecated)” in the heading) that the The reason I’m asking is that I hope that it's not a real deprecation and I hope to get this confirmed. I can see the point of the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hello! We plan to get rid of The PR removing it is here and there's also provisional list of expected changes in next major release. It has been sitting there for a while — no one likes introducing breaking changes frequently. Despite future removal from # desired strategy to call handlers for applied events
class MyStrategy
def call(aggregate, event)
aggregate.method(apply_handler_name(event.event_type)).call(event)
end
private
def apply_handler_name(event_type)
"apply_#{to_snake_case(last_namespace_part_of(event_type))}"
end
def last_namespace_part_of(event_type)
event_type.split(/::|\./).last
end
def to_snake_case(string)
# ...
end
end
# passing desired strategy to included AggregateRoot module
class SomeAggregate
include AggregateRoot.with_strategy(lambda { MyStrategy.new })
end
# or via custom module to hide the plumbing
module MyAggregateRoot
def self.included(base)
base.include AggregateRoot.with_strategy(lambda { MyStrategy.new })
end
end
class SomeAggregate
include MyAggregateRoot
end
Can you please give me an example of that? Do you perhaps mean asserting on |
Beta Was this translation helpful? Give feedback.
-
Btw. there's a repository of different aggregate implementation beyond AggregateRoot at https://github.com/arkency/aggregates |
Beta Was this translation helpful? Give feedback.
Hello!
We plan to get rid of
apply_
methods approach inaggregate_root
in RES 3.0 release (next major release introducing breaking changes). The timeline is not set in stone and we'll definitely add deprecation notices to last releases in RES 2.x line. The documentation went ahead since it is probably the first place people may learn aboutapply_
method handlers.The PR removing it is here and there's also provisional list of expected changes in next major release. It has been sitting there for a while — no one likes introducing breaking changes frequently.
Despite future removal from
aggregate_root
you could still continue using this approach. It is a matter of providing desired apply st…