I've created following abstraction for scheduling jobs:
public interface IJobData
{ }
public interface IJob<in TJobData> where TJobData : IJobData
{
Task ExecuteAsync(TJobData jobData);
}
I use this in the application layer to create jobs. E.g.
public record ForgotPasswordJobData() : IJobData;
public class ForgotPasswordJob : IJob<ForgotPasswordJobData>
{
public Task ExecuteAsync(ForgotPasswordJobData jobData)
{
// Do some work
return Task.CompletedTask;
}
}
Now I want to decorate the ExecuteAsync method with
[AutomaticRetry(Attempts = 5)]
However I dont want to put it in the application layer, because this will create a dependency on the infrastructure layer. AutomaticRetry is a feature of the hangfire library, which sits in the infrastructure layer.
Is there a way to abstract [AutomaticRetry(Attempts = 5)]
in the application layer?