尝试了解事件聚合器模式 [英] Trying to understand the event aggregator pattern

查看:214
本文介绍了尝试了解事件聚合器模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以简单的方式实现事件聚合器模式,以逐步了解它。但是我没有找到任何书或漂亮的视频教程来谈论它的实现。

我刚刚发现了一些很好的文章,如这个 http://weblogs.asp.net/rashid/archive/2009/ 03/05 / use-event-aggregator-to-make-your-application-more-extensible.aspx http://martinfowler.com/eaaDev/EventAggregator.html 第一篇文章太大了,不能让我理解模式,第二篇文章没有完成:)。

由我创建了我的课程的方式:

I am trying to implement the event aggregator pattern in a simple way to learn it step by step. But i didn't find any book or nice video tutorial talking about it's implementation.
I just found some good articles such as this http://weblogs.asp.net/rashid/archive/2009/03/05/use-event-aggregator-to-make-your-application-more-extensible.aspx and http://martinfowler.com/eaaDev/EventAggregator.html the first article is too big to let me understand the pattern and the second one is not completed :).
By the way i created my classes:

public class Member
{
    public int ID { get; set; }

    public string UserName { get; set; }
}

public class MemberService
{
    public void CommentSubmited()
    {
        // increase member score and do some other logic.
    }
}

public class Comment
{
    public int ID { get; set; }

    public string CommentBody { get; set; }

    public Member ByMember { get; set; }
}

public class CommentService
{
    public void SubmitNewComment(Member member, string commentBody, EventAggregator eventAggregator)
    {
        Comment comment = new Comment();
        comment.ByMember = member;
        comment.CommentBody = commentBody;

        db.SaveComment(comment); // save comment to the db

        //eventAggregator.GetEvent<CommentSubmited>.Fire();
    }
}

public class EventAggregator
{
    public void RegisterEvent()
    {

    }

    public void RemoveEvent()
    {

    }
}

我想要的是创建一个通用的方式,以便当有一个新的注释创建了 CommentSubmited()方法到Fire。 br>
我想要它通用,因为稍后会有更多的服务,例如RateService,QuestionService,....,每个都有一个 XXXSubmited()方法在MemberService类中。

And what i want is to create a generic way so that when ever a new comment created the CommentSubmited() method to Fire.
I want it generic because there will be more services later such as RateService, QuestionService, .... and each one will have a XXXSubmited() method in the MemberService class.

希望你了解我想要学习的东西,问我是否要让我更清楚。

Hope you understood what i want to learn, ask me if you want me to make things more clear.

请注意,我查看了通用代表主题,并认为这可能会帮助我在这个问题,但不能像我想要的那样。

Note i checked the Generic Delegates topic and thought it may help me in this issue, but couldn't make it as i wanted.

推荐答案

检查出来使用Rx发布在一个简单的事件聚合器上:事件聚合器无效扩展

Check out this post on a simple event aggregator using Rx: Event Aggregator with Reactive Extensions

这篇关于尝试了解事件聚合器模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆