Do not use constructor injection in Aggregate Roots

An Aggregate Root is a unit of encapsulation, and its internals should not be available as external services that can be re-used. This is why the Aggregate Root has a constructor with a single parameter (the EventSourceId) and does not support adding more constructor-injected parameters.

This may feel strange the first time you encounter it if you are familiar with working with IoC -containers and using Dependency Injection and programming against interfaces to keep your classes small and testable. That is fine, you are not wrong, those are good things.

However, the Aggregate Root has the role of being the single point of interaction for its internals, and is supposed to fully obscure its internals to its surroundings. This is why (in this case) you should new up any services or objects you need inside it, and not let that be handled by the surroundings.

If you need something that you can only use in an injected fashion, like a service that handles a shared resource you cannot create inside the Aggregate Root you do this by taking the dependency as an argument to the method that needs it.

Examples:

public class some_transactional_thing : AggregateRoot
{
    some_service _service_the_aggregate_root_needs;

    public some_transactional_thing(EventSourceId id)
    {
        _service_the_aggregate_root_needs = new some_service(id);
    }

    public void do_something_that_needs_a_shared_service(
        shared_service service_from_the_caller, 
        domain_class some_data_from_the_command
    )
    {
        var something = _service_the_aggregate_root_needs.get_something(
            some_data_from_the_command.an_id_for_the_internal_service
        );

        service_from_the_caller.do_a_thing_with(something);
    }
}

Also, remember that the Aggregate Root is the EventSource, so any internal services cannot apply events. Rather they should return the events to their “mother” so she can apply them.