BackgroundService on Clean Architecture

14 hours ago 1
ARTICLE AD BOX

I’m using Clean architecture, and I want to create an background service to do something in background each 10-20 minutes.

This BackgroundService resolve a dependency with the ServiceProvider; and I got an Application Service from my Application layer, that is where I have my logic for the background proccess.

So in the Presentantion Layer I register my BakgroundService with build.Services.AddHostedService<>(), but what I'm not sure at all if my public class SomeBackgroundService : BackgroundService should be on the Presentation Layer or Infrastructure Layer?

I thought could be on Infrastructure Layer, but you have to install the Microsoft.Extension.Hosting.Abstractions in the layer, and in the Preesentation Layer that package comes by default with the .net sdk.

So, at the end, this "backgroundService", could be just an .ps1 or .bash script, and configure it with crontab or with Task Scheduler on windows, but I decided put the logic directly in my backend.

So, which is the cleaner layer to put the BackgroundService?

Thanks.

Read Entire Article