Skip to content

Instantly share code, notes, and snippets.

@AnthonyMastrean
Created October 25, 2012 14:13
Show Gist options
  • Save AnthonyMastrean/3952776 to your computer and use it in GitHub Desktop.
Save AnthonyMastrean/3952776 to your computer and use it in GitHub Desktop.
Request handler redux
public interface IAmAnAction
{
void Handle(dynamic data = null);
}
public class OrchestrationAction : IAmAnAction
{
readonly IDoSomething _collaborator;
public OrchestratorOrchestrationAction(IDoSomething collaborator)
{
_collaborator = collaborator;
}
public void Handle(dynamic data)
{
_collaborator.execute(data.Number);
}
}
public class Q<T>
where T : IAmAnAction
{
private readonly IContainer _container;
private readonly Queue<Action> _queue = new Queue<Action>();
public Q(IContainer container)
{
_container = container;
}
public void Enqueue<TCommand>(dynamic data)
where TCommand : T
{
_queue.Enqueue(() => _container.GetInstance<TCommand>().Handle(data));
}
public void Consume()
{
_queue.Dequeue()();
}
}
public static class Runner
{
static Q<IAmAnAction> _enqueue;
public static void QueueAnEvent()
{
dynamic data = new ExpandoObject();
data.Number = 10;
_enqueue.Enqueue<OrchestrationAction>(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment