C# - 管道式事件模型
在 ASP.NET Web 应用程序中,事件按特定顺序触发:
为了简单起见 Load =>验证 => 回发 => 渲染
假设我想开发这样的管道式事件
示例:
事件 1 [ "观众正在聚集" ,各位{ 事件 2 和事件 3 请等待我发出信号 }]
事件 1 完成任务后
事件 2 [ { 事件 2, 事件 3 "观众聚集!我的任务结束了 } ]
事件 2 正在接管控制权以执行其任务
事件 2 [ " 观众正在登录 "事件 3 请等待,直到我发出信号]
在事件 2 完成任务之后
.....
事件 3 [“Jon skeet 的演示结束:)”]
任何人都可以通过非常基本的示例来解释,如何才能我设计这个?
In ASP.NET Web Apps , events are fired in particluar order :
for simplicity Load => validation =>postback =>rendering
Suppose I want to develop such pipeline -styled event
Example :
Event 1 [ "Audiance are gathering" ,Guys{ Event 2 and Event 3 Please wait until i signal }]
after Event 1 finished it task
Event 2 [ { Event 2, Event 3 "Audiance gathered! My task is over } ]
Event 2 is taking over the control to perform its task
Event 2 [ " Audiance are Logging in " Event 3 please wait until i signal ]
after Event 2 finished it task
.....
Event 3 [ "Presentation By Jon skeet is Over :) "]
With very basic example can anybody explain ,how can i design this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此示例展示了如何采用简单的抽象类和处理程序列表上的简单扩展方法,并实现您正在讨论的管道模型。 这当然是一个简单的示例,因为我只是将一个字符串作为事件数据传递给它。 但显然您可以根据您的情况进行定制。
扩展方法
RaiseEvent
枚举处理程序列表,并调用处理程序上的Handle
方法来通知该事件。This example shows how you can take a simple abstract class, and a simple extension method on a list of handlers, and implement the pipeline model you're talking about. This is of course a trivialized example as I'm simply passing it a string as the event data. but you can obviously customize to suit your situation.
the extension method
RaiseEvent
enumerates over the list of handlers and calls theHandle
method on the handler to notify it of the event.Windows Workflow Foundation 就是为此而设计的。 这里有 2 个截屏视频,您可以看看如何实现这样的事情。
http://blog.wekeroad.com/mvc-storefront/mvcstore-part -19a/
http://blog.wekeroad.com/ mvc-storefront/mvcstore-part-21/
Windows Workflow Foundation is designed to do just this. There's 2 screencasts here you can take a look at on how to implement something like this.
http://blog.wekeroad.com/mvc-storefront/mvcstore-part-19a/
http://blog.wekeroad.com/mvc-storefront/mvcstore-part-21/
一个非常简单的解决方案,也接近 ASP.NET 中实际发生的情况:
A very simple solution, that is also close to what actually happens in ASP.NET: