I have two aggregate roots... AR1 and AR2. AR1 holds a collection of references (IDs) to instances of AR2. Inside one of the AR1 methods a domain event is raised to update the collection of AR2 instances. The domain event is raised after the transaction completes using a technique mentioned here: http://www.jayway.com/2013/06/20/dont-publish-domain-events-return-them everything works as expected.
My issue is this: The method I am calling from the domain event to update AR2 is currently public (can't be internal) as the domain event is executing in my application service layer (different assembly to my business logic layer). I only ever want this method executed by the domain event and nothing else.
How would I go about doing this?
You could ask for event object as an argument to the AR2 method. That will be a good indicator that the method should only be called as the result of a raised event.
public void someMethod(SomeOccuredEvent event)
We can see this approach being used in Effective Aggregate Design Part III in the Implementing Eventual Consistency section.