Caliburn.Micro IEventAggregator Publish method missing an overload
Asked Answered
E

1

9

I'm working through some tutorials online learning Caliburn.Micro for the first time. Some of the tutorials are using the older 1.3.0 version, I'm using the newer 2.0.0.6 version which was the latest Nuget package which is likely the source of this discrepancy:

When trying to publish the following message:

public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)));
}

The compiler throws an error saying that the overload wasn't found. The only overload for Publish that is available has the following signature: void Publish(object message, Action marshal)

I got this to work by using the background worker thread method shown below but in my case it seems like overkill. Was the single parameter overload really removed from Caliburn.Micro?

Also, the documentation is here: https://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator still show examples using the more basic, single parameter example where you simply pass a message. Is the documentation at this link the latest that correctly describes 2.0.0.6?

public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)), 
action => Task.Factory.StartNew(action));
}

Finally, for bonus points:

What is this 2nd parameter good for other than publishing the message on a background thread? Can someone give some other example(s) of what this overload can be used for?

Edmead answered 8/6, 2014 at 14:19 Comment(0)
O
11

In Caliburn Micro version 2.0, the EventAggregator.Publish method also takes an action to marshal the event. To maintain the pre-2.0 behavior, you should switch to the EventAggregator.PublishOnUIThread method instead. See the migration instructions here for information on incompatibilities between 1.5 and 2.0.

In general, I believe that the Codeplex documentation is a little bit outdated. Please refer to the new dedicated web site for most up-to-date documentation.

Orcus answered 8/6, 2014 at 15:8 Comment(2)
there is no EventAggregator.PublishOnUIThread in the 2.0.2 :(Jillian
I've managed it with .Publish(value, new EventAggregator().PublishOnUIThread) where PublishOnUIThread is an extention method from Caliburn.Micro.EventAggregatorExtensions namespaceJillian

© 2022 - 2024 — McMap. All rights reserved.