Skip to content

Instantly share code, notes, and snippets.

@obegendi
Last active April 16, 2022 09:33
Show Gist options
  • Save obegendi/378e7c0a7985178277bfde56ffc6e363 to your computer and use it in GitHub Desktop.
Save obegendi/378e7c0a7985178277bfde56ffc6e363 to your computer and use it in GitHub Desktop.
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