title: Aggregate as a service
body: <p>Assume scenario where the service requires some global configuration to handle some request. </p>
  
  <p>For example when user wants to do something it requires some global configuration to check whether the user is permited todo so.</p>
  
  <p>I realize that in axon i can have command handlers that could handle commands without specified target aggregate so the handling part isn't a problem.</p>
  
  <p>Problem is where i would like to have persistent storage on top of that and some invariants when trying to change the configuration. The whole idea of the configuration is that it should be consistent like aggregate in axon.</p>
  
  <pre><code>ConfigService {
  @Inject
  configRepository;
  @Inject
  eventGateway;
  
  @CommandHandler
  handle(changeConfig){
  let current = configRepository.loadCurrent;
  //some checks
  
  //persist here?
  eventGateway.send(confgChanged)
  }
  
  @EventHandler
  on(configChanged){
  //or persist here?
  configRepository.saveCurrent(configChanged.data)
  }
  
  }
  </code></pre>
  
  <p>If I do persistance on the command handler I think I shouldn't use event handler because it would save it twice. But then when i somehow lose the config repository data i can rebuild it based on the events.</p>
  
  <p>Im not sure what im missing here in the understanding of the DDD concepts, to put it simply i would like to know where to put command handler for something that is neither an aggregate nor entity. 
  Maybe i should create command handler that calls the Config service instead making config service the command handler.</p>