Last active
April 16, 2022 09:33
-
-
Save obegendi/378e7c0a7985178277bfde56ffc6e363 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IJobCommand{ | |
int JobId { get; set; } | |
void Execute(); | |
} | |
public interface QueryJob : IJobCommand{ | |
int JobId { get; set; } = 121; | |
//kısa vadede yapınızı bozmamak için buradan resolve edilebilir. | |
string Namespace { get; set; } = "Resolver"; | |
public void Execute(){ | |
// Make awesome stuff | |
} | |
} | |
public interface IJobCommandResolver{ | |
IJobCommand Resolve(int jobId); | |
} | |
public class JobCommandResolver : IJobCommandResolver{ | |
private readonly IEnumerable<IJobCommand> _commands; | |
public Resolver(IEnumerable<IJobCommand> commands){ | |
_commands = commands; | |
} | |
public IJobCommand Resolve(int jobId){ | |
var command = _commands.FirstOrDefault(command => command.JobId == jobId); | |
if(command is null) return null; | |
else return command; | |
} | |
} | |
public class JobProvider{ | |
public async Task LoadEndExecuteJobs(){ | |
var jobs = await GetFromDb(); | |
foreach(var item in jobs){ | |
var command = Resolver.Resolve(item.JobId); | |
if(command is null) continue; | |
command.Execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment