Hey Josh,
I just commented on your blog with 2 questions. Would love if you can reply there. In the mean time I will try that myself, thanks!!
Laurent
From:
wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On
Behalf Of Josh Smith
Sent: Tuesday, April 07, 2009 6:18 AM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
Hey all,
No virus
found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.11.43/2043 - Release Date: 04/06/09
06:22:00
Just curious, did any of you guys try NInject or another Dependency Injection framework to solve this kind of issues? I know I promised I would write about it, and didn’t have time yet, but with NInject you get a central repository of objects, which provides an easy access to them. For example, if you create a MainViewModel and a SecondaryViewModel using NInject, you can then easily get the SecondaryViewModel from the MainViewModel and call methods on it directly.
NInject adds a little overhead to the application (especially in Silverlight where size matters), but offers the advantage of a well known, well tested framework to solve this kind of issues. In addition, it is very easy to create a design time view model vs a runtime view model, and to keep the design time implementation separate.
Just curious to hear your thoughts, and yes I will write about it, I promise J
Laurent
Version: 8.0.238 / Virus Database: 270.11.43/2043 - Release Date: 04/06/09 18:59:00
I am currently writing a MSDN article on Prism (which uses Unity’s DI container, but you could use Ninject or other container) and it solves this issue with a typical IoC model but also for Silverlight allows you to specify modules in .xap files that can be downloaded behind the scenes or on demand. Prism encompasses other problems (I like the DelegateCommand<> and EventAggregator a lot too). In this way I think Prism solves a lot of problems for WPF, but the ondemand and componentization at the .xap level loading of silverlight projects make it a home run for Silverlight IMHO.
Thanks,
Shawn Wildermuth
Microsoft MVP (C#), MCSD.NET, Author and Speaker
The Silverlight Tour is coming to a city near you!
-----Original Message-----
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
On Behalf Of Shawn Wildermuth
Sent: Tuesday, April 07, 2009 11:49 AM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
I am currently writing a MSDN article on Prism (which uses Unity's DI
container, but you could use Ninject or other container) and it solves
this issue with a typical IoC model but also for Silverlight allows you
to specify modules in .xap files that can be downloaded behind the
scenes or on demand. Prism encompasses other problems (I like the
DelegateCommand<> and EventAggregator a lot too). In this way I think
Prism solves a lot of problems for WPF, but the ondemand and
componentization at the .xap level loading of silverlight projects make
it a home run for Silverlight IMHO.
Thanks,
Shawn Wildermuth
http://wildermuth.com <http://wildermuth.com/>
https://agilitrain.com <http://wildermuthconsulting.com/>
Microsoft MVP (C#), MCSD.NET, Author and Speaker
The Silverlight Tour <http://www.silverlight-tour.com/> is coming to a
Hey guys,
I don’t really prefer attribute-based approaches in general, I guess this is my alt.net hidden side speaking LOL. I am currently experimenting with a combination if interface/implementation based messages, and the WeakReference approach that Josh describes. Maybe it can provide an alternative.
Cheers,
Laurent
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Sacha Barber
Sent: Tuesday, April 07, 2009 2:50 PM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
Yes I see bit from all of us in there.
GREAT
Date: Tue, 7 Apr 2009 08:43:40 -0400
Subject: [WPF Disciples] Re: New Mediator
From: flappl...@gmail.com
To: wpf-di...@googlegroups.com
As Karl/KDAWG/Keith mentioned to me yesterday, this is the real power of the
Disciples. The fact that passionate people all over the world can easily
collaborate on projects like this is fantastic.. :)
Josh
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.11.44/2044 - Release Date: 04/06/09 18:59:00
Sorry I couldn’t get into this yesterday.
I’ll get my head around this tonight and see where I land.
Marlon great point about partial trust.
This is solvable.
kdawg
On Mon, Apr 6, 2009 at 10:53 PM, Marlon Grech <marlo...@gmail.com> wrote:
hehe... I already have the code in my mind.... all I need is 5 minutes to write it :P haha....
but let's wait for the other Disciples to put their input....
P.S And yes mike it is do able.... I already did this in a sample app with a similar setup.... in the example I wrote the parameter is a constant which is the way you should define a Mediator message.
On Mon, Apr 6, 2009 at 10:51 PM, Josh Smith <flappl...@gmail.com> wrote:
In Marlon's setup, the message IDs can be const strings exposed off some class. That should work ok.
On Mon, Apr 6, 2009 at 4:50 PM, Mike Brown <mbro...@gmail.com> wrote:
Remember you can't use a parameter to an Attribute unless it's a compile time constant or an enum.
On Mon, Apr 6, 2009 at 4:45 PM, Marlon Grech <marlo...@gmail.com> wrote:
I like this....
I would do it a bit different.... (or the same as you are saying which would mean I didn't understand correctly, which is most likely the case here :) )
something like this
class MyVM
{
[MediatorNotification(MediatorMessages.Message1]
public void Test(object args )
{
....
}
public MyVM()
{
Mediator.Register(this);
}
}
the register would scan the VM and register all the methods to the messages. This way you only scan once.... what do you think? I think we are saying the same thing
On Mon, Apr 6, 2009 at 10:35 PM, Josh Smith <flappl...@gmail.com> wrote:
I think it would be better to decorate the callback methods of the Colleagues with an attribute, and specify the message ID in the attribute's constructor. In your Mediator/WeakDelegate code, scan the Target object (i.e. Colleague) for a method decorated with your custom attribute, where the MessageID equals the message of interest. This is better than passing in the method name to the Mediator for the following reasons:
1) The method names on the Colleagues classes are not duplicated in the code. If you change the name of the callback, you don't have to remember to change the method name passed to the Mediator.
2) The Colleague class's are more self-documenting, because the callback methods are attributed with the Message ID that they are associated with.
3) The callback locating logic is simplified, because you don't have to worry about things like method overloads.
What do you think?
Josh
I got one implementation working, need to refine it, then I will blog about it. It is based on the following concepts:
IMessage<T>: this is an interface that defines the message to be broadcasted. It has one property of type T named Content
IMessageRecipient: This is the interface that all message recipients must implement. In a WPF application, the ViewModels will typically be IMessageRecipients. One method void ReceiveMessage<T>(IMessage<T> message);
Messenger: This is the mediator. It keeps a list of WeakReferences on IMessageRecipients. It has a method Register(IMessageRecipient recipient, Type messageType) for registration, and a method Broadcast<U, T>(U message) where U : IMessage<T> for broadcast
Then there is a list of messages, for example public class EditMessage : IMessage<CustomerViewModel>
This Edit message tells a VM that it should now set its DataContext to the Content (of type CustomerViewModel). In a typical LOB application, I have SaveMessage, EditMessage, LoadMessage, and we can even define a GenericMessage that looks like public class GenericMessage : IMessage<object>
I can easily unit test my mediator. The last thing which I am still not too happy about is the best way for the IMessageRecipient to get a reference on the mediator. For the moment I store one instance in the App resources, I could of course also use a Singleton. What is your suggestion?
Cheers,
Laurent
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Josh Smith
Sent: Tuesday, April 07, 2009 3:48 PM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
The more implementations to
compare, the better. I am hoping that every Disciple who is interested in
this will blog their Mediator implementation, and then we can compare them all
to come up with the optimal design. And, as Bill pointed out, we should
also compare ours to the EventAggregator in Prism/CAL.
Josh
Yep, good thinking. Using the App store or a Singleton works fine too. I am implementing a LOB example based on my WCF service I demoed at MIX. It works really well so far.
No virus found in this incoming message..
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.11.44/2044 - Release Date: 04/06/09 18:59:00
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.11.44/2044 - Release Date: 04/06/09
18:59:00
Folks,
One day away from the list and nearly 70 messages!, I must admit that I’ve gone lost about the mediator thread and I have not seen latest release yet (link please?...)
Just one opinion: What I like in MVVM compared with Prism/Caliburn is simplicity, If I have to add IOC/PostSharp and other stuff to have it working, I agree with Shawn that probably it’s better to consider stable solutions like Prism/Caliburn.
What I really like about MVVM is that, starting from a simple ViewModelBase (similar at the one Kent’s just blogged about) and a bunch of RelayCommands I can do “almost” everything.
Mediator is of course the missing part to close the loop but it must remains as flexible (and easy to understand) as RelayCommand, so the lighter, the better (IMHO).
Speaking about mediator how do you suggest its use:
1-Mediator connects only Viewmodels associated to the same view.
2-Mediator is a singleton inside application and its shared among all viewmodels.
3-Each viewmodel in a view share a mediator and all views are coordinated by another “cross-view” mediator.
4-Other
Sorry if answer is already in available code, but as I’ve said, haven’t looked at it yet.
-Corrado
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Josh Smith
Sent: martedì 7 aprile 2009 20:14
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
I just checked out
EventAggregator, and must agree, that it is quite awesome. I think we're
wasting time working on a new Mediator implementation, before looking at
EA. It already does what we're doing, even has a WeakAction equivalent
known as DelegateReference. I can see the need perhaps for a lighter
version, like how my RelayCommand is a lighter version of DelegateCommand in
Prism.
Josh
Hey Corrado,
I like # 2 (one mediator for the application) except that so far I didn’t implement it as a singleton, but I store one instance in the Application’s resources. Making a singleton forces me to implement the class this way, and I don’t want to have this restriction. Just I case, I want to be able to have multiple mediators in my application if needed (performances, etc…)
For example I could imagine having one mediator to let windows’ viewmodels communicate together (that one would be saved in the App resources) and then one “sub mediator” per window, saved in the Window’s resources, for communication between the user controls within the Window.
So far I got good results with the mediator implementation I am working on, I like its simplicity as you say. MVVM + RelayCommand + simple mediator, that really rocks. Super elegant solution.
Cheers,
Laurent
No virus found in this incoming message.
Hi Laurent,
Thanks for the explanation, I’ll have a look at your solution when ready.
Corrado
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Laurent Bugnion,
GalaSoft [MVP, MCP]
Sent: martedì 7 aprile 2009 22:10
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
Hey Corrado,
I like # 2 (one mediator for the application) except that so far I didn’t implement it as a singleton, but I store one instance in the Application’s resources. Making a singleton forces me to implement the class this way, and I don’t want to have this restriction. Just I case, I want to be able to have multiple mediators in my application if needed (performances, etc…)
For example I could imagine having one mediator to let windows’ viewmodels communicate together (that one would be saved in the App resources) and then one “sub mediator” per window, saved in the Window’s resources, for communication between the user controls within the Window.
So far I got good results with the mediator implementation I am working on, I like its simplicity as you say. MVVM + RelayCommand + simple mediator, that really rocks. Super elegant solution.
Cheers,
Laurent
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Corrado Cavalli
Sent: Tuesday, April 07, 2009 9:22 PM
No virus found in this incoming message.
Agree, Singleton was just an example but exposing it from Application class might be a valid alternative.
I know that mediator is just a message dispatcher but I was just wondering whether a “single mediator” vs “group of mediators talking each other at higher level” would be a better approach from an architectural point of view.
-Corrado
From: wpf-di...@googlegroups.com
[mailto:wpf-di...@googlegroups.com] On Behalf Of Marlon Grech
Sent: mercoledì 8 aprile 2009 08:58
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator
Corrado,
The way I see it is that you are giving far too importance to the
Mediator.... You shouldn't really care if there is 1 or 6 or 1000
mediator instances in your application (ok if there are a lot there will be a
lot of memory usage for nothing :) ). All you care about is that you can
publish a Message (with same arguments) and others can receive the message....
Think about this as if it was a chat room... If I want to send you a message I
don't care if it is MSN, Gtalk or any other thing as long as the message gets
through. The mediator is just a way how message between the ViewModels gets
through. I think it's totally up to the developers need to constuct the
Mediator as they want, Singelton, stored in App.Resources whatever. The
mediator implementation should not specify how the Mediator should be
created.... Obviously there must be some kind of guidance and that is why I
implemented it as a Singleton the first time....
I am about to finish my latest implementation of the Mediator and post it over
for you guys to see.... Yesterday I was about to finish it but I had to go
out....
Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
On Wed, Apr 8, 2009 at 6:20 AM, Corrado Cavalli <corrado...@gmail.com> wrote:
I agree. The implementation is not very important. I like mine (duh) because it is easy to extend and to test, but I will take any implementation if it works.
Marlon “had to go out” instead of programming WPF. Tst tst tst and so it starts…
.... in Order to Register for a message from a VM you do the following
Mediator.Instance.Register(MediatorMessages.Message1, this, "Test");
anyway I attached a project that demos this... have a look and tell me what you think..... once we agree on this I will publish this as an update to my article....
P.S I am using strings not an enum. I do this becuase strings can be defined in other projects then the Mediator project.... I see a Mediator as a chat room.... A chat room does not know what messages are passing... the people chatting define those.... Mediator for me is similar
Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
--
Quidquid latine dictum sit, altum sonatur.
- Whatever is said in Latin sounds profound.
War is peace. Freedom is slavery. Bugs are features.
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.11.44/2044 - Release Date: 04/06/09
18:59:00
Dinner? Sissy ;) Real programmers use perfusions to get nutrients!
I changed my implementation to offer a DefaultInstance of the mediator and a set of static methods using this default instance. This way you can easily make sure that you are using the same instance throughout the application, but if you like you can create multiple instances.