I have a business requirement that any account viewed needs to be logged. I'm trying to figure out where this requirement should be in my code. This is a query type event and doesn't require going through the entity itself like most of my domain events.
Should I encapsulate all of my repositories into domain services that my application service will call?
public class AccountService
{
private readonly IAccountRepository repository;
private readonly IDomainEventDispatcher dispatcher;
public AccountService(IAccountRepository repository, IDomainEventDispatcher dispatcher)
{
this.repository = repository;
this.dispatcher = dispatcher;
}
public Account ViewAccount(Guid Id)
{
var account = repository.GetById(Id);
dispatcher.Raise(new AccountViewedEvent(account));
return account;
}
}
Is there another way to handle this?
It seems like a lot of layers to have an application service call a domain service that calls a repository.