When validating within aggregates sometimes we need information which
is provided by query repositories, hence we have to inject them into
the aggregates, I was wondering when/how to inject those query
repositories since aggregates are loaded from aggregate repository.
this is primarily a domain of personal preference. Some people like to inject domain objects with infrastructural objects, such as repositories, services, etc. An alternative (and my preference) is to have the command handler use these services to get the data and pass that as parameters to the methods that need them. If a domain class really needs a service, I pass the implementation of that service as a method parameter.
If you want to inject resources into your aggregates, there are a few options. One is to use the SpringPrototypeEventSourcingRepository, which uses a Spring-defined propotype bean to inject resources. The other is to create a specialized implementation of a Repository (the AbstractEventSourcingRepository only has one abstract method) that injects resources just prior to returning the reconstructed instance. If you don’t use event sourcing, extend the AbstractRepository (or one of the more specialized subclasses) to do the job.