I have a event-sourced CRM application where users can be subscribed to newsletters.
We want to implement a command where the customer can unsubscribe or subscribe using a form by entering their email address. As my Customer aggregate is keyed by its ID, from the event-store side, I can only load a customer using their ID.
Therefore, I need to query the read-side from the command to look up their ID and then load the Customer using the ID from the event store.
My read-side is very simple, it is essentially a bunch of SQL queries reaching directly into the database and returning data in their appropriate format.
I am considering 2 ways:
1. Have some service like LookUpCustomerIDByEmail() to find the ID. Then use the ID in CustomerRepository.GetByID(). These would be called in the command handler. Would the LookUpCustomerIDByEmail service be part of the read side or the command side?
2. Implement it as part of the repository: CustomerRepository.GetByEmail(). The first way is to inject the query service into the repository as part of its constructor: new CustomerRepostory(LookUpCustomerIDByEmailService). The second way would be to use it like so: CustomerRepository.GetByEmail(someEmail, LookUpCustomerByEmailService).
Which way would be the best way to do this? Are there better alternatives?