[CaliburnMicro] Dependencies attribute on any depth level of properties

I didn't post anything on the blog for a very long time (2010-12-07), so let's break the silence with something new about Caliburn Micro.

In this post, I will briefly show you an update of an "old" article I wrote. The main drawback of the previous version of this dependencies attribute was its inability to make the availability of the action depend on more than one level.

For example, you could write these dependencies, which update the availability of the Do method when either OtherProperty (a property of the same view-model than Do) or OtherProperty.ChildProperty were modified.

[code lang="csharp"][Dependencies("OtherProperty", "OtherProperty.ChildProperty")] public IEnumerable Do() { }[/code] With the new Dependencies attribute I'll show you right after the break, you won't be limited to this single level of hierarchy, thus allowing you to write a dependency like:

[code lang="csharp"][Dependencies("OtherProperty.ChildProperty.OneMoreLevelProperty.LastLevelProperty.*")] public IEnumerable Do() { }[/code]

[PostSharp] [Caliburn] Automatic IEventPublisher subscription and publication

If you develop in WPF using the MVVM pattern, you have certainly heard about the Event Aggregator pattern, which allows, as the MSDN says:

decoupling of publishers and subscribers so they can evolve independently.

There are several implementations of this pattern:

Of course, as the title of this article told you, we are going to use the latter, and I will propose an implementation of a PostSharp aspect which will help us to subscribe to events, publish them, and dispose the subscriptions when the view-model is deactivated.

[Caliburn Micro] Action filters - Dependencies on "properties of properties", using the Reactive Extensions

By default, Caliburn Micro (CM) doesn't contain the action filters which belong to Caliburn (C). There is a recipe on how to implement them back in CM, but unfortunately it doesn't cover all the initial functionalities which are in C.

One feature missing, and that I needed, is the possibility to depend on "properties of properties".

With the recipe, you can add a dependency between the property of a view-model (VM) and another property of this same VM. Thus, when the latter property is changed, the PropertyChanged event of the VM is fired, resulting in the update of the availability of the action on which the Dependencies attribute is put. But what it doesn't allow you to do, is to define something like:

[code lang="csharp"][Dependencies("OtherProperty.ChildProperty")][/code] This would update the availability of the action if OtherProperty implements INotifyPropertyChanged and if the ChildProperty is modified. You could even use something like:

[code lang="csharp"][Dependencies("OtherProperty.*")][/code] which would update the availability if any of the properties of OtherProperty is modified.

But let me show you how I implemented this feature on top of the recipe, with the great use of the Reactive Extensions.