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

  • SEARCH
  • Home
  • 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 391073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:01:34+00:00 2026-05-12T16:01:34+00:00

Ok, this question is for people with either a deep knowledge of PRISM or

  • 0

Ok,

this question is for people with either a deep knowledge of PRISM or some magic skills I just lack (yet). The Background is simple: Prism allows the declaration of events to which the user can subscribe or publish. In code this looks like this:

  _eventAggregator.GetEvent<LayoutChangedEvent>().Subscribe(UpdateUi, true);
  _eventAggregator.GetEvent<LayoutChangedEvent>().Publish("Some argument");

Now this is nice, especially because these events are strongly typed, and the declaration is a piece of cake:

public class LayoutChangedEvent : CompositePresentationEvent<string>
{
}

But now comes the hard part: I want to trace events in some way. I had the idea to subscribe using a lambda expression calling a simple log message. Worked perfectly in WPF, but in Silverlight there is some method access error (took me some time to figure out the reason).. If you want to see for yourself, try this in Silverlight:

eA.GetEvent<VideoStartedEvent>().Subscribe(obj => TraceEvent(obj, "vSe", log));

If this would be possible, I would be happy, because I could easily trace all events using a single line to subscribe. But it does not… The alternative approach is writing a different functions for each event, and assign this function to the events. Why different functions? Well, I need to know WHICH event was published. If I use the same function for two different events I only get the payload as argument. I have now way to figure out which event caused the tracing message.

I tried:

  • using Reflection to get the causing event (not working)
  • using a constructor in the event to enable each event to trace itself (not allowed)

Any other ideas?
Chris

PS: Writing this text took me most likely longer than writing 20 functions for my 20 events, but I refuse to give up 🙂 I just had the idea to use postsharp, that would most likely work (although I am not sure, perhaps I end up having only information about the base class).. Tricky and so unimportant topic…

  • 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-05-12T16:01:35+00:00Added an answer on May 12, 2026 at 4:01 pm

    Probably the easiest thing would be to subclass CompositePresentationEvent and override the behavior of the Publish event. Here’s the source for CompositePresentationEvent:
    http://compositewpf.codeplex.com/SourceControl/changeset/view/26112#496659

    Here’s the current Publish behavior:

    public virtual void Publish(TPayload payload)
    {
         base.InternalPublish(payload);
    }
    

    So you could just add a little to this:

    public virtual override void Publish(TPayload payload)
    {
         ILoggerFacade logger = ServiceLocator.Current.GetInstance<ILoggerFacade>();
         logger.Log("Publishing " + payload.ToString(), Category.Debug, Priority.Low);
         base.InternalPublish(payload);
    }
    

    Here I’m using the logger facility built into Prism, but feel free to substitute your own (or better, just implement ILoggerFacade!).

    I was surprised that there were any default messages being published or places to plug in tracing in this system… as much as EventAggregator is abused by people, you’d think this would be a big request!

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

Sidebar

Related Questions

Some people have mentioned RockScroll and MetaScroll in This Question , but those only
This question goes beoynd just programming, but I'd like to get some input on
I asked this question to multiple people and until now I do not have
This question is for the people who know both Haskell (or any other functional
This question is something that a lot of people learning bioinformatics and new to
I have read numerous people with this question and have tried numerous strategies. However,
I recently asked this question: MS SQL share identity seed amongst tables (Many people
I asked this question over Security site, and people there suggested I should have
I've found a few other people asking this question, but the answers for their
Ok , so many people are asking this question, and there are many approaches

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.