tags:

views:

32

answers:

1

Are handlers reused to proceed another message?

public abstract class SomeHandler : IHandleMessages<MyEvent>
{
    public IBus Bus { get; set; }
    public String Message { get; set; }

    public void Handle(T message)
    {
        Message = "Test";
        SomeInstanceMethod();
    }

    public void SomeInstanceMethod()
    {
        if (Message = ...) // Can i use Message here?
            return;
    }
}
+1  A: 

By default, message handlers are configured as ComponentCallModelEnum.Singlecall, which means that each call on the component will be performed on a new instance.

So, two messages will be processed by different instances of the class and cannot share state.

However, what you have here is setting a class property and then calling another method in the class that retrieves that property. That would work fine. However, in my opinion, that is kind of confusing, and if that is what you're after, you're probably better off passing values to another method as a parameter.

David
Thank you David. About your point on passing the values as parameters: the code i provided is just a help to my question. I agree that in real life this code shouldn't exist.
Rationalle