Dependency Injection in a .NET 6 class project without controllers and HTTP

Microsoft's hosting has a concept of hosted services to handle background tasks, so you can turn your FileListener into hosted service and register it in DI with AddHostedService and the hosting will start it automatically with DI and cancelation signaling support.

Note that consuming scoped services from the hosted service requires a little bit extra work.