main
1using Gorilla.Commons.Infrastructure.Container;
2using gorilla.commons.utility;
3using MoMoney.Service.Infrastructure.Threading;
4
5namespace MoMoney.Presentation.Presenters
6{
7 public interface ICommandPump
8 {
9 ICommandPump run<Command>() where Command : gorilla.commons.utility.Command;
10 ICommandPump run<Command, T>(T input) where Command : ParameterizedCommand<T>;
11 ICommandPump run<Output, Query>(Callback<Output> item) where Query : Query<Output>;
12 }
13
14 public class CommandPump : ICommandPump
15 {
16 readonly CommandProcessor processor;
17 readonly DependencyRegistry registry;
18 readonly ICommandFactory factory;
19
20 public CommandPump(CommandProcessor processor, DependencyRegistry registry, ICommandFactory factory)
21 {
22 this.processor = processor;
23 this.factory = factory;
24 this.registry = registry;
25 }
26
27 public ICommandPump run<Command>() where Command : gorilla.commons.utility.Command
28 {
29 return run(registry.get_a<Command>());
30 }
31
32 public ICommandPump run<Command>(Command command) where Command : gorilla.commons.utility.Command
33 {
34 processor.add(command);
35 return this;
36 }
37
38 public ICommandPump run<Command, T>(T input) where Command : ParameterizedCommand<T>
39 {
40 processor.add(() => registry.get_a<Command>().run(input));
41 return this;
42 }
43
44 public ICommandPump run<T>(Callback<T> item, Query<T> query)
45 {
46 return run(factory.create_for(item, query));
47 }
48
49 public ICommandPump run<Output, Query>(Callback<Output> item) where Query : Query<Output>
50 {
51 return run(item, registry.get_a<Query>());
52 }
53 }
54}