Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
New Mediator
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 73 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Marlon Grech  
View profile  
 More options Apr 6, 3:56 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 21:56:14 +0200
Local: Mon, Apr 6 2009 3:56 pm
Subject: New Mediator

Hi all,

Today I had a few minutes to think about the "Memory Leak" in the Mediator
implementation I did. I implemented a new version that solves this issue. I
am not 100% happy since my solution uses Reflection (yes I love reflection
and end up fitting it everywhere).

Basically the memory leak is solved by using a WeakReference and then using
reflection to call a method on the WeakRefernce Target. This way GC can
collect the ViewModel when it is not being used any more and the Mediator
can check if the ViewModel is alive or not (and if not remove it from the
InvocationList)

here is the WeakDelegate (Josh suggested this name I was gonna go for
something crazy such as WeakCollogueInvoker :) lol haha)

class WeakDelegate : WeakReference
        {
            public string Method { get; private set; }

            private MethodInfo methodInfo;

            public WeakDelegate(object target, string method)
                : base(target)
            {
                Method = method;
                methodInfo = Target.GetType().GetMethod(Method,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.Static);
                if (methodInfo == null)
                    throw new
InvalidOperationException(String.Format("Method {0} was not found on target
object", Method));
            }

            public void Notify(object args)
            {
                if (IsAlive)
                    methodInfo.Invoke(Target, new[] { args });
            }
        }

... and here is how the Mediator does the invocation / cleanup

if (invocationList.ContainsKey(message))
            {
                for (int i = 0; i < invocationList[message].Count; i++)
                {
                    var weakDelegate = invocationList[message][i];
                    if (weakDelegate.IsAlive)
                        weakDelegate.Notify(args);
                    else//remove the weak delegate from the invokation list
                    {
                        invocationList[message].RemoveAt(i);
                        i--;
                    }
                }
            }

... 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/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 3:58 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 21:58:06 +0200
Local: Mon, Apr 6 2009 3:58 pm
Subject: Re: New Mediator

oops... forgot to attach the file :D

hihi :D

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

  MediatorTest.zip.rename2
61K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 6, 3:59 pm
From: Josh Smith <flappleja...@gmail.com>
Date: Mon, 6 Apr 2009 15:59:44 -0400
Local: Mon, Apr 6 2009 3:59 pm
Subject: Re: [WPF Disciples] Re: New Mediator

I don't think you should include the 'Static' binding flag.  The callbacks
will always be instance methods on the Target object, no?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 4:00 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 22:00:29 +0200
Local: Mon, Apr 6 2009 4:00 pm
Subject: Re: New Mediator

and yes I know this would blow up in a PartialTrust CAS.....

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 4:01 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 22:01:49 +0200
Local: Mon, Apr 6 2009 4:01 pm
Subject: Re: [WPF Disciples] Re: New Mediator

I did that jsut in case someone wants to define a method like this

public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

otherwise reflection would not get that method...

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 6, 4:35 pm
From: Josh Smith <flappleja...@gmail.com>
Date: Mon, 6 Apr 2009 16:35:35 -0400
Local: Mon, Apr 6 2009 4:35 pm
Subject: Re: [WPF Disciples] New Mediator

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 4:45 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 22:45:47 +0200
Local: Mon, Apr 6 2009 4:45 pm
Subject: Re: [WPF Disciples] Re: New Mediator

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

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Brown  
View profile  
 More options Apr 6, 4:49 pm
From: Mike Brown <mbrow...@gmail.com>
Date: Mon, 6 Apr 2009 16:49:13 -0400
Local: Mon, Apr 6 2009 4:49 pm
Subject: Re: [WPF Disciples] Re: New Mediator

I think that's a brilliant idea Josh...however, how would the registration
occur? Another alternative would be to use that static reflection trick that
I posted for INPC<http://mbrownchicago.spaces.live.com/blog/cns!2221DC39E0C749A4!1285.e...>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Brown  
View profile  
 More options Apr 6, 4:50 pm
From: Mike Brown <mbrow...@gmail.com>
Date: Mon, 6 Apr 2009 16:50:29 -0400
Local: Mon, Apr 6 2009 4:50 pm
Subject: Re: [WPF Disciples] Re: New Mediator

Remember you can't use a parameter to an Attribute unless it's a compile
time constant or an enum.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 6, 4:50 pm
From: Josh Smith <flappleja...@gmail.com>
Date: Mon, 6 Apr 2009 16:50:54 -0400
Local: Mon, Apr 6 2009 4:50 pm
Subject: Re: [WPF Disciples] Re: New Mediator

I'm not sure.  I might want to register/unregister for certain messages at
certain times. Then again, I could put logic into my callbacks that aborts
if i don't want to act on some message at the time.  Hmm...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 6, 4:51 pm
From: Josh Smith <flappleja...@gmail.com>
Date: Mon, 6 Apr 2009 16:51:47 -0400
Local: Mon, Apr 6 2009 4:51 pm
Subject: Re: [WPF Disciples] Re: New Mediator

In Marlon's setup, the message IDs can be const strings exposed off some
class.  That should work ok.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 4:53 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 22:53:59 +0200
Local: Mon, Apr 6 2009 4:53 pm
Subject: Re: [WPF Disciples] Re: New Mediator

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.

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 5:16 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 23:16:28 +0200
Local: Mon, Apr 6 2009 5:16 pm
Subject: Re: [WPF Disciples] Re: New Mediator

couldn't help it... otherwise would not sleep...

here is the new Register method

public void Register(object target)
        {
            foreach (var methodInfo in
target.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static))
                foreach (RegisterMediatorMessageAttribute attribute in
methodInfo.GetCustomAttributes(typeof(RegisterMediatorMessageAttribute),
true))
                    invocationList.AddValue(attribute.Message, new
WeakDelegate(target, methodInfo.Name));
        }

... The Attribute

[AttributeUsage(AttributeTargets.Method)]
    public class RegisterMediatorMessageAttribute : Attribute
    {
        public string Message { get; set; }

        public RegisterMediatorMessageAttribute(string message)
        {
            Message = message;
        }
    }

... and now the cool part

How the VM uses this
class ColleagueA {
        public ColleagueA()
        {
            Mediator.Instance.Register(this);
        }

        [RegisterMediatorMessage(MediatorMessages.Message1)]
        public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

What do you think guys?

P.S in a real world application this  Mediator.Instance.Register(this); will
not be in every VM because it would be in the BaseViewModel (or at least i
would put it there so that you don't have to call it every time)

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Brown  
View profile  
 More options Apr 6, 5:28 pm
From: Mike Brown <mbrow...@gmail.com>
Date: Mon, 6 Apr 2009 17:28:52 -0400
Local: Mon, Apr 6 2009 5:28 pm
Subject: Re: [WPF Disciples] Re: New Mediator

I wonder if that would scale out to where the Mediator would be some kind of
service on another machine. That would work well in that scenario Udi Dahan
talked about in this month's
MSDN.<http://msdn.microsoft.com/en-us/magazine/dd569749.aspx>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 6, 5:32 pm
From: Marlon Grech <marlongr...@gmail.com>
Date: Mon, 6 Apr 2009 23:32:19 +0200
Local: Mon, Apr 6 2009 5:32 pm
Subject: Re: [WPF Disciples] Re: New Mediator

Why would you want the Mediator as a service on another machine? I don't
think this needs that kind of scalability

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Brown  
View profile  
 More options Apr 6, 6:42 pm
From: Mike Brown <mbrow...@gmail.com>
Date: Mon, 6 Apr 2009 18:42:54 -0400
Local: Mon, Apr 6 2009 6:42 pm
Subject: Re: [WPF Disciples] Re: New Mediator

Look at the article I linked to. That's a perfect example of how a
distributed mediator would be a good thing.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 7, 12:17 am
From: Josh Smith <flappleja...@gmail.com>
Date: Tue, 7 Apr 2009 00:17:32 -0400
Local: Tues, Apr 7 2009 12:17 am
Subject: Re: [WPF Disciples] Re: New Mediator

Hey all,

I set aside some time tonight to work on the Mediator problem.  I refined
Marlon's awesome solution, and removed the need for using reflection to
locate the target method.  I posted an entry on my blog, showing the
prototype, and asked for suggestions/improvements/bugs/etc.  If I get any
good feedback on it, I'll send them your way.

Here's the blog post:

http://joshsmithonwpf.wordpress.com/2009/04/06/a-mediator-prototype-f...

Josh


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sacha Barber  
View profile  
 More options Apr 7, 3:41 am
From: Sacha Barber <sachabar...@hotmail.com>
Date: Tue, 7 Apr 2009 07:41:27 +0000
Local: Tues, Apr 7 2009 3:41 am
Subject: RE: [WPF Disciples] Re: New Mediator

Marlon

I like Joshes idea of attributes, let us know when we have some new code to look at.

Date: Mon, 6 Apr 2009 18:42:54 -0400
Subject: [WPF Disciples] Re: New Mediator
From: mbrow...@gmail.com
To: wpf-disciples@googlegroups.com

Look at the article I linked to. That's a perfect example of how a distributed mediator would be a good thing.

On Mon, Apr 6, 2009 at 5:32 PM, Marlon Grech <marlongr...@gmail.com> wrote:

Why would you want the Mediator as a service on another machine? I don't think this needs that kind of scalability

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 11:28 PM, Mike Brown <mbrow...@gmail.com> wrote:

I wonder if that would scale out to where the Mediator would be some kind of service on another machine. That would work well in that scenario Udi Dahan talked about in this month's MSDN.

On Mon, Apr 6, 2009 at 4:53 PM, Marlon Grech <marlongr...@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.

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:51 PM, Josh Smith <flappleja...@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 <mbrow...@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 <marlongr...@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

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:35 PM, Josh Smith <flappleja...@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

On Mon, Apr 6, 2009 at 3:56 PM, Marlon Grech <marlongr...@gmail.com> wrote:

Hi all,

Today I had a few minutes to think about the "Memory Leak" in the Mediator implementation I did. I implemented a new version that solves this issue. I am not 100% happy since my solution uses Reflection (yes I love reflection and end up fitting it everywhere).

Basically the memory leak is solved by using a WeakReference and then using reflection to call a method on the WeakRefernce Target. This way GC can collect the ViewModel when it is not being used any more and the Mediator can check if the ViewModel is alive or not (and if not remove it from the InvocationList)

here is the WeakDelegate (Josh suggested this name I was gonna go for something crazy such as WeakCollogueInvoker :) lol haha)

class WeakDelegate : WeakReference
        {
            public string Method { get; private set; }

            private MethodInfo methodInfo;

            public WeakDelegate(object target, string method)
                : base(target)
            {
                Method = method;
                methodInfo = Target.GetType().GetMethod(Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                if (methodInfo == null)
                    throw new InvalidOperationException(String.Format("Method {0} was not found on target object", Method));
            }

            public void Notify(object args)

            {
                if (IsAlive)
                    methodInfo.Invoke(Target, new[] { args });
            }
        }

... and here is how the Mediator does the invocation / cleanup

if (invocationList.ContainsKey(message))

            {
                for (int i = 0; i < invocationList[message].Count; i++)
                {
                    var weakDelegate = invocationList[message][i];
                    if (weakDelegate.IsAlive)

                        weakDelegate.Notify(args);
                    else//remove the weak delegate from the invokation list
                    {
                        invocationList[message].RemoveAt(i);

                        i--;
                    }
                }
            }

... 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/

_________________________________________________________________
Beyond Hotmail — see what else you can do with Windows Live.
http://clk.atdmt.com/UKM/go/134665375/direct/01/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 7, 3:44 am
From: Marlon Grech <marlongr...@gmail.com>
Date: Tue, 7 Apr 2009 09:44:56 +0200
Local: Tues, Apr 7 2009 3:44 am
Subject: Re: [WPF Disciples] Re: New Mediator

I posted the code yesterday.... here let me attach it again

here is the new Register method

public void Register(object target)
        {
            foreach (var methodInfo in
target.GetType().GetMethods(BindingFlags.NonPublic
| BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                foreach (RegisterMediatorMessageAttribute attribute in
methodInfo.GetCustomAttributes(typeof(RegisterMediatorMessageAttribute),
true))
                    invocationList.AddValue(attribute.Message, new
WeakDelegate(target, methodInfo.Name));
        }

... The Attribute

[AttributeUsage(AttributeTargets.Method)]
    public class RegisterMediatorMessageAttribute : Attribute
    {
        public string Message { get; set; }

        public RegisterMediatorMessageAttribute(string message)
        {
            Message = message;
        }
    }

... and now the cool part

How the VM uses this
class ColleagueA {
        public ColleagueA()
        {
            Mediator.Instance.Register(this);
        }

        [RegisterMediatorMessage(MediatorMessages.Message1)]
        public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Tue, Apr 7, 2009 at 9:41 AM, Sacha Barber <sachabar...@hotmail.com>wrote:

  MediatorTest.zip.rename2
63K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marlon Grech  
View profile  
 More options Apr 7, 3:46 am
From: Marlon Grech <marlongr...@gmail.com>
Date: Tue, 7 Apr 2009 09:46:16 +0200
Local: Tues, Apr 7 2009 3:46 am
Subject: Re: [WPF Disciples] Re: New Mediator

Josh,

Maybe I am missing something but your solution still would blow up in
Partial trust... Delegate.CreateDelegate is still reflection at the end of
the day no? (It still has CAS for ReflectionPermission)

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent Bugnion, GalaSoft [MVP, MCP]  
View profile  
 More options Apr 7, 5:05 am
From: "Laurent Bugnion, GalaSoft [MVP, MCP]" <laur...@galasoft.ch>
Date: Tue, 7 Apr 2009 11:05:26 +0200
Local: Tues, Apr 7 2009 5:05 am
Subject: RE: [WPF Disciples] Re: New Mediator

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-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Josh Smith
Sent: Tuesday, April 07, 2009 6:18 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

Hey all,

I set aside some time tonight to work on the Mediator problem.  I refined
Marlon's awesome solution, and removed the need for using reflection to
locate the target method.  I posted an entry on my blog, showing the
prototype, and asked for suggestions/improvements/bugs/etc.  If I get any
good feedback on it, I'll send them your way.

Here's the blog post:

http://joshsmithonwpf.wordpress.com/2009/04/06/a-mediator-prototype-f...
apps/

Josh

On Mon, Apr 6, 2009 at 5:16 PM, Marlon Grech <marlongr...@gmail.com> wrote:

couldn't help it... otherwise would not sleep...

here is the new Register method

public void Register(object target)
        {
            foreach (var methodInfo in
target.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static))
                foreach (RegisterMediatorMessageAttribute attribute in
methodInfo.GetCustomAttributes(typeof(RegisterMediatorMessageAttribute),
true))
                    invocationList.AddValue(attribute.Message, new
WeakDelegate(target, methodInfo.Name));
        }

... The Attribute

[AttributeUsage(AttributeTargets.Method)]
    public class RegisterMediatorMessageAttribute : Attribute
    {
        public string Message { get; set; }

        public RegisterMediatorMessageAttribute(string message)
        {
            Message = message;
        }
    }

... and now the cool part

How the VM uses this
class ColleagueA {
        public ColleagueA()
        {
            Mediator.Instance.Register(this);
        }

        [RegisterMediatorMessage(MediatorMessages.Message1)]

        public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

What do you think guys?

P.S in a real world application this  Mediator.Instance.Register(this); will
not be in every VM because it would be in the BaseViewModel (or at least i
would put it there so that you don't have to call it every time)

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:53 PM, Marlon Grech <marlongr...@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.

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:51 PM, Josh Smith <flappleja...@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 <mbrow...@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 <marlongr...@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

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:35 PM, Josh Smith <flappleja...@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

On Mon, Apr 6, 2009 at 3:56 PM, Marlon Grech <marlongr...@gmail.com> wrote:

Hi all,

Today I had a few minutes to think about the "Memory Leak" in the Mediator
implementation I did. I implemented a new version that solves this issue. I
am not 100% happy since my solution uses Reflection (yes I love reflection
and end up fitting it everywhere).

Basically the memory leak is solved by using a WeakReference and then using
reflection to call a method on the WeakRefernce Target. This way GC can
collect the ViewModel when it is not being used any more and the Mediator
can check if the ViewModel is alive or not (and if not remove it from the
InvocationList)

here is the WeakDelegate (Josh suggested this name I was gonna go for
something crazy such as WeakCollogueInvoker :) lol haha)

class WeakDelegate : WeakReference
        {
            public string Method { get; private set; }

            private MethodInfo methodInfo;

            public WeakDelegate(object target, string method)
                : base(target)
            {
                Method = method;
                methodInfo = Target.GetType().GetMethod(Method,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.Static);
                if (methodInfo == null)
                    throw new
InvalidOperationException(String.Format("Method {0} was not found on target
object", Method));
            }

            public void Notify(object args)
            {
                if (IsAlive)
                    methodInfo.Invoke(Target, new[] { args });
            }
        }

... and here is how the Mediator does the invocation / cleanup

if (invocationList.ContainsKey(message))
            {
                for (int i = 0; i < invocationList[message].Count; i++)
                {
                    var weakDelegate = invocationList[message][i];
                    if (weakDelegate.IsAlive)
                        weakDelegate.Notify(args);
                    else//remove the weak delegate from the invokation list
                    {
                        invocationList[message].RemoveAt(i);
                        i--;
                    }
                }
            }

... 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/

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent Bugnion, GalaSoft [MVP, MCP]  
View profile  
 More options Apr 7, 5:31 am
From: "Laurent Bugnion, GalaSoft [MVP, MCP]" <laur...@galasoft.ch>
Date: Tue, 7 Apr 2009 11:31:49 +0200
Local: Tues, Apr 7 2009 5:31 am
Subject: RE: [WPF Disciples] Re: New Mediator

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

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Laurent Bugnion, GalaSoft [MVP, MCP]
Sent: Tuesday, April 07, 2009 11:05 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

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-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Josh Smith
Sent: Tuesday, April 07, 2009 6:18 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

Hey all,

I set aside some time tonight to work on the Mediator problem.  I refined
Marlon's awesome solution, and removed the need for using reflection to
locate the target method.  I posted an entry on my blog, showing the
prototype, and asked for suggestions/improvements/bugs/etc.  If I get any
good feedback on it, I'll send them your way.

Here's the blog post:

http://joshsmithonwpf.wordpress.com/2009/04/06/a-mediator-prototype-f...
apps/

Josh

On Mon, Apr 6, 2009 at 5:16 PM, Marlon Grech <marlongr...@gmail.com> wrote:

couldn't help it... otherwise would not sleep...

here is the new Register method

public void Register(object target)
        {
            foreach (var methodInfo in
target.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static))
                foreach (RegisterMediatorMessageAttribute attribute in
methodInfo.GetCustomAttributes(typeof(RegisterMediatorMessageAttribute),
true))
                    invocationList.AddValue(attribute.Message, new
WeakDelegate(target, methodInfo.Name));
        }

... The Attribute

[AttributeUsage(AttributeTargets.Method)]
    public class RegisterMediatorMessageAttribute : Attribute
    {
        public string Message { get; set; }

        public RegisterMediatorMessageAttribute(string message)
        {
            Message = message;
        }
    }

... and now the cool part

How the VM uses this
class ColleagueA {
        public ColleagueA()
        {
            Mediator.Instance.Register(this);
        }

        [RegisterMediatorMessage(MediatorMessages.Message1)]

        public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

What do you think guys?

P.S in a real world application this  Mediator.Instance.Register(this); will
not be in every VM because it would be in the BaseViewModel (or at least i
would put it there so that you don't have to call it every time)

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:53 PM, Marlon Grech <marlongr...@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.

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:51 PM, Josh Smith <flappleja...@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 <mbrow...@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 <marlongr...@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

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:35 PM, Josh Smith <flappleja...@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

On Mon, Apr 6, 2009 at 3:56 PM, Marlon Grech <marlongr...@gmail.com> wrote:

Hi all,

Today I had a few minutes to think about the "Memory Leak" in the Mediator
implementation I did. I implemented a new version that solves this issue. I
am not 100% happy since my solution uses Reflection (yes I love reflection
and end up fitting it everywhere).

Basically the memory leak is solved by using a WeakReference and then using
reflection to call a method on the WeakRefernce Target. This way GC can
collect the ViewModel when it is not being used any more and the Mediator
can check if the ViewModel is alive or not (and if not remove it from the
InvocationList)

here is the WeakDelegate (Josh suggested this name I was gonna go for
something crazy such as WeakCollogueInvoker :) lol haha)

class WeakDelegate : WeakReference
        {
            public string Method { get; private set; }

            private MethodInfo methodInfo;

            public WeakDelegate(object target, string method)
                : base(target)
            {
                Method = method;
                methodInfo = Target.GetType().GetMethod(Method,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.Static);
                if (methodInfo == null)
                    throw new
InvalidOperationException(String.Format("Method {0} was not found on target
object", Method));
            }

            public void Notify(object args)
            {
                if (IsAlive)
                    methodInfo.Invoke(Target, new[] { args });
            }
        }

... and here is how the Mediator does the invocation / cleanup

if (invocationList.ContainsKey(message))
            {
                for (int i = 0; i < invocationList[message].Count; i++)
                {
                    var weakDelegate = invocationList[message][i];
                    if (weakDelegate.IsAlive)
                        weakDelegate.Notify(args);
                    else//remove the weak delegate from the invokation list
                    {
                        invocationList[message].RemoveAt(i);
                        i--;
                    }
                }
            }

... 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/

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

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
18:59:00


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shawn Wildermuth  
View profile  
 More options Apr 7, 5:49 am
From: "Shawn Wildermuth" <sh...@wildermuth.com>
Date: Tue, 7 Apr 2009 05:49:08 -0400
Local: Tues, Apr 7 2009 5:49 am
Subject: RE: [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 city
near you!

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Laurent Bugnion, GalaSoft [MVP, MCP]
Sent: Tuesday, April 07, 2009 5:32 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

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

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Laurent Bugnion, GalaSoft [MVP, MCP]
Sent: Tuesday, April 07, 2009 11:05 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

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-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Josh Smith
Sent: Tuesday, April 07, 2009 6:18 AM
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] Re: New Mediator

Hey all,

I set aside some time tonight to work on the Mediator problem.  I refined
Marlon's awesome solution, and removed the need for using reflection to
locate the target method.  I posted an entry on my blog, showing the
prototype, and asked for suggestions/improvements/bugs/etc.  If I get any
good feedback on it, I'll send them your way.

Here's the blog post:

http://joshsmithonwpf.wordpress.com/2009/04/06/a-mediator-prototype-f...
apps/

Josh

On Mon, Apr 6, 2009 at 5:16 PM, Marlon Grech <marlongr...@gmail.com> wrote:

couldn't help it... otherwise would not sleep...

here is the new Register method

public void Register(object target)
        {
            foreach (var methodInfo in
target.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static))
                foreach (RegisterMediatorMessageAttribute attribute in
methodInfo.GetCustomAttributes(typeof(RegisterMediatorMessageAttribute),
true))
                    invocationList.AddValue(attribute.Message, new
WeakDelegate(target, methodInfo.Name));
        }

... The Attribute

[AttributeUsage(AttributeTargets.Method)]
    public class RegisterMediatorMessageAttribute : Attribute
    {
        public string Message { get; set; }

        public RegisterMediatorMessageAttribute(string message)
        {
            Message = message;
        }
    }

... and now the cool part

How the VM uses this
class ColleagueA {
        public ColleagueA()
        {
            Mediator.Instance.Register(this);
        }

        [RegisterMediatorMessage(MediatorMessages.Message1)]

        public static void Test(object test)
        {
            MessageBox.Show("Message from mediator");
        }

What do you think guys?

P.S in a real world application this  Mediator.Instance.Register(this); will
not be in every VM because it would be in the BaseViewModel (or at least i
would put it there so that you don't have to call it every time)

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:53 PM, Marlon Grech <marlongr...@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.

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:51 PM, Josh Smith <flappleja...@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 <mbrow...@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 <marlongr...@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

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/

On Mon, Apr 6, 2009 at 10:35 PM, Josh Smith <flappleja...@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

On Mon, Apr 6, 2009 at 3:56 PM, Marlon Grech <marlongr...@gmail.com> wrote:

Hi all,

Today I had a few minutes to think about the "Memory Leak" in the Mediator
implementation I did. I implemented a new version that solves this issue. I
am not 100% happy since my solution uses Reflection (yes I love reflection
and end up fitting it everywhere).

Basically the memory leak is solved by using a WeakReference and then using
reflection to call a method on the WeakRefernce Target. This way GC can
collect the ViewModel when it is not being used any more and the Mediator
can check if the ViewModel is alive or not (and if not remove it from the
InvocationList)

here is the WeakDelegate (Josh suggested this name I was gonna go for
something crazy such as WeakCollogueInvoker :) lol haha)

class WeakDelegate : WeakReference
        {
            public string Method { get; private set; }

            private MethodInfo methodInfo;

            public WeakDelegate(object target, string method)
                : base(target)
            {
                Method = method;
                methodInfo = Target.GetType().GetMethod(Method,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
BindingFlags.Static);
                if (methodInfo == null)
                    throw new
InvalidOperationException(String.Format("Method {0} was not found on target
object", Method));
            }

            public void Notify(object args)
            {
                if (IsAlive)
                    methodInfo.Invoke(Target, new[] { args });
            }
        }

... and here is how the Mediator does the invocation / cleanup

if (invocationList.ContainsKey(message))
            {
                for (int i = 0; i < invocationList[message].Count; i++)
                {
                    var weakDelegate = invocationList[message][i];
                    if (weakDelegate.IsAlive)
                        weakDelegate.Notify(args);
                    else//remove the weak delegate from the invokation list
                    {
                        invocationList[message].RemoveAt(i);
                        i--;
                    }
                }
            }

... 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
...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent Bugnion, GalaSoft [MVP, MCP]  
View profile  
 More options Apr 7, 6:20 am
From: "Laurent Bugnion, GalaSoft [MVP, MCP]" <laur...@galasoft.ch>
Date: Tue, 7 Apr 2009 12:20:35 +0200
Local: Tues, Apr 7 2009 6:20 am
Subject: RE: [WPF Disciples] Re: New Mediator
Yes the solution I experimented with NInject worked like a charm for
Silverlight too.

...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Apr 7, 8:11 am
From: Josh Smith <flappleja...@gmail.com>
Date: Tue, 7 Apr 2009 08:11:05 -0400
Local: Tues, Apr 7 2009 8:11 am
Subject: Re: [WPF Disciples] Re: New Mediator

Yeah, that's true, but it doesn't use MethodInfo.Invoke(), which is supposed
to be slower than CreateDelegate + invoking a delegate (according to the
info I saw on the Web, which isn't necessarily correct!).  I'm not too
worried about the permissions thing, but the performance is something worth
considering.

Josh


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 73   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google