Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:26:30+00:00 2026-06-15T21:26:30+00:00

I attempted to implement my own simple event aggregator recently. I got a lot

  • 0

I attempted to implement my own simple event aggregator recently. I got a lot of inspiration from the event aggregator article on MSDN. There is one thing that I notice about the event aggregator on MSDN is the events are actually classes on their own. This isn’t really a bad thing at all. However, I just find it awkward to always create a new empty class for every single little event.

The reason I find it awkward is because of the need to create a class for every single granular event. A mouse click event, for instance, would have double_click, single_click, left_click, right_click, etc. And all of these are going to have a class of its own. It gets messy after a while.

So in my own implementation, I thought I could make it in such a way where the ClickEvent is a class, but all the granular events related to the Click event would then be “types” of the ClickEvent. In this case, the “types” are enum. The usage would look something like this:

//Publisher
eventAggregator.GetEvent<ClickEvent>.Publish(ClickEventType.Double_Click, eventArgs);

//Subscriber
eventAggregator.GetEvent<ClickEvent>.Subscribe(ClickEventType.Double_Click, handlerMethod);

However, I’m not sure if this implementation defeats the whole purpose of having a strongly typed event? Now, it seems like the ClickEvent is merely a container for the different event enum types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:26:31+00:00Added an answer on June 15, 2026 at 9:26 pm

    Yes it does (seem like a container that is) – your handler will fire regardless of the click type and there will be some code required in the handler to determine the type of click, which makes things a little messier.

    If your issue is mostly the organisation of the files/classes and keeping the code tidy, why not just create the click events as nested classes within a main click class

    e.g.

    public static class ClickEvents // Prevent instantiation
    {
        public class SingleLeft { }
        public class SingleRight { }
        public class DoubleLeft { }
        public class DoubleRight { }
        // Are there any more click events possible?!
    }
    
    eventAggregator.GetEvent<ClickEvents.SingleLeft>.Publish();
    

    Aside from that, it’s the uniqueness of the type that determines the event signature, and therefore multiple types are required to satisfy this particular implementation

    At least the above keeps your handler code clean

    void HandleLeftClick()
    {
    }
    

    vs

    void HandleClick(ClickArgs e) 
    {
        if(e.ClickType == ClickType.Left)
        {
        }
    }
    

    Edit:

    Also remember that you can subscribe multiple events to the same handler if you want to handle more than one click type:

    eventAggregator.GetEvent<ClickEvents.SingleLeft>.Subscribe(HandlerMethod);
    eventAggregator.GetEvent<ClickEvents.SingleRight>.Subscribe(HandlerMethod);
    

    (this would work in the rare situation that the subscriber didn’t care which mouse button was clicked)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the examples from the CGI::Session::Auth::DBI and CGI::Session::Auth pages, I have attempted to implement
Attempted translation of the above question from non-native English to English: This is a
I'm running spring security 2.0.3 and i need to implement a simple dictionary attack
I been reading a lot on how to implement UDP hole punching but fore
I'm am getting ready to attempt to implement Scripting Bridge for the first time,
consider the following code, which represents an attempt to implement partial matching. the intended
I'm looking to implement a warning if the user attempts to leave the order
I am trying to implement an OutOfStockException for when the user attempts to buy
I attempted to generate a migration like: rails generate migration RemovefromGenotypes box:integer well:string but
I attempted to re-size two buttons in MSIE, so they would be extra-large but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.