Which layer should scheduled task be put?

2019-06-07 12:52发布

问题:

I'm trying to implement DDD application with layered architecture. I have:

  • Infrastructure layer - a layer which implements technology specific parts of the application.
  • Domain layer - a layer which contains domain model.
  • Application layer - a layer which contains interferences to interact with domain model.
  • And interfaces layer - a layer which receives events from the outside.

The classic 3 layer (+ infrastructure) architecture is quite clear. But my application isn't very classic. Beside UI I have scheduled task which should be ran periodically. I thought about putting such tasks into interfaces layer, because these task actually handle events like UI. But there is a problem, I can't make decision which layer I should put an scheduler which fire events for scheduled tasks.

I draw a sketch

Which layer should I put the scheduler object? Or may be where is another way to design application with internal event generator.

回答1:

To me, scheduler is a host for task executor (in the same way as your JSP container is a host for you UI). I would model it as an external entity and implement it as another infrastructure project.