command-pattern

Dependency Injection when using the Command Pattern

陌路散爱 提交于 2019-12-12 09:33:34
问题 I'm using the Command Pattern for the first time. I'm a little unsure how I should handle dependencies. In the code below, we dispatch a CreateProductCommand which is then queued to be executed at a later time. The command encapsulates all the information it needs to execute. In this case it is likely we will need to access a data store of some type to create the product. My question is, how do I inject this dependency into the command so that it can execute? public interface ICommand { void

Using template template parameter on function call

↘锁芯ラ 提交于 2019-12-12 04:23:36
问题 Actually, all the answers are nice, and informative but they don't solve my particular problem. I don't think that's the fault of the very helpful people who replied but instead, I badly phrased my question. Therefore I decided to post a completely new question with more relevant code examples here : Mixing Command pattern, Factory pattern and templates all together ... . If anyone cares to look ... Now the original question : I dont think it's possible to do what I want but I ask, just in

Can I make a keyed service for AutoFac based on the type of the Open Generic

流过昼夜 提交于 2019-12-11 13:52:12
问题 I would like to make a keyedService based on the T for my Open Generic ICommandHandler. I would like to register a ConsultatCommandHanlder keyed service when the ICommandHandler has a T that inherits from ConsultantCommand Any idea how to do it? Or if it is even possible? I am new to AutoFac and am struggling. I am presently registering CommandHandler like this: //Register All Command Handlers builder.RegisterAssemblyTypes(assemblies) .As( t => t.GetInterfaces() .Where(a => a.IsClosedTypeOf

What is the Action Design Pattern?

天大地大妈咪最大 提交于 2019-12-10 12:48:59
问题 What is the Action Design Pattern, I haven't heard of it before? I am suspecting it is the same as the Command Design pattern [wikipedia] but I can't find any resources on it. 回答1: You're right, action pattern == command pattern. You hear it called the action pattern more often in GUI design, in the form "on some button pressed, perform this action". In the code the button would be wired up with an action object of some kind. 回答2: I'm reading "The Action/Executor Pattern" at MSDN right now,

How to share the same context with different threads in multi-Command Pattern in C#?

南楼画角 提交于 2019-12-10 01:58:57
问题 There is an extended implementation of command pattern to support multi-commands (groups) in C#: var ctx= //the context object I am sharing... var commandGroup1 = new MultiItemCommand(ctx, new List<ICommand> { new Command1(ctx), new Command2(ctx) }); var commandGroup2 = new MultiItemCommand(ctx, new List<ICommand> { new Command3(ctx), new Command4(ctx) }); var groups = new MultiCommand(new List<ICommand> { commandGroup1 , commandGroup2 }, null); Now , the execution is like: groups.Execute();

Command Design Pattern - Is Invoker Optional?

拟墨画扇 提交于 2019-12-09 09:10:48
问题 Is Invoker class optional in Command design pattern? Client needs to instantiate Concrete Command and Receiver for the command. Does client always need to instantiate Invoker and pass on the command object to Invoker object. Later on whenever client needs to execute the command, client just asks Invoker object and Invoker performs the command (maybe immediately or may queue the command for later execution). Or is this other way around? If client needs to perform the command synchronously,

Client Server Command Design pattern with variable delays

亡梦爱人 提交于 2019-12-08 06:13:43
问题 I am writing a client program to control a server which is in turn controlling some large hardware. The server needs to receive commands to initialize, start, stop and control the hardware. The connection from the client to the server is via a TCP or UDP socket. Each command is encapsulated in an appropriate message using a SCADA protocol (e.g. Modbus or DNP3). Part of the initialization phase involves sending a sequence of commands from the client to the server. In some cases there must be a

JRuby: command pattern in Java with Ruby block: why does it work?

家住魔仙堡 提交于 2019-12-08 02:06:06
问题 I am learning how to integrate Java library with Ruby code and come to the following question. I have a command pattern implemented in Java, as follows: public interface Command { public String execute(String param); } public class CommandRunner { public String run(Command cmd, String param) { return cmd.execute(param)+" [this is added by run method]"; } } When I import that to JRuby program I can implement Ruby class that respond_to? :execute with one parameter and pass it to the

Command Pattern in GOF vs CQRS meanings

a 夏天 提交于 2019-12-07 09:28:27
问题 When Looking at the command pattern a found a slight difference. May be some is able to more clearify this. When looking at Gang Of Four it says that each command has a Execute Method see for example: http://www.blackwasp.co.uk/Command.aspx like: myCommand.Execute(myValue); Now when i look at the commands how there are used in CQRS (Greg Young) i see that this commands don't have an execute method. They are only some kind of "Command Instruction" instance. Similar things are said in the CQRS

What is the accepted pattern for WPF commanding in MVVM?

99封情书 提交于 2019-12-07 01:16:49
问题 I'm working on a WPF app and I understand the command pattern pretty well, but I've found that there are several different implementations of the command pattern for MVVM. There's Josh Smith's implementation in his WPF sample app, the DelegateCommand from Prism, and the CommandBindings implementation. My question is, what is the generally accepted best practice for using commands with MVVM? My application uses Prism so DelegateCommand is available to us. The devs on my team are arguing about