How to transport difference message to the MyCustomHandler

Topics: Policy Injection Application Block
Jun 24, 2011 at 2:51 AM

Hi All,

Now I had custom a callhandler as MyCustomHandler. I will transport difference message with every interceported method.

I can realize it with the CallHandlerAttribute such as:

[MyCustomHandler("Login Success","Login")]

public void Login(string login);

[MyCustomHandler("Save Success","Save")]

public void Save(string save).

 

But I want to know How to realize it with the configuration, and I don't want to config one callhandler with every object.

<callHandler name="MyCustomHandler" type="EntLibStudy.Helper.EntLibExtension.PolicyInjectionExtension.MyCustomHandler, EntLibStudy.Helper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<constructor>
<param name="message" type="System.String" value="I'm a save method, not login. Please don't notice me Login Success.">
</param>
<param name="parameterName" type="System.String" value=" ">
</param>
</constructor>
</callHandler>

 

Can anyone help me. I will be very appreciate for your help.

Best Regards.

David

Jun 24, 2011 at 1:40 PM

Hope someone can help me!

Jun 24, 2011 at 4:08 PM

Hi David,

Yes, you should be able to do this in the configuration but you should make sure that there is also an existing constructor in your Custom Call Handler that expects the same parameter arguments you're setting up in the config. Lets say for example;

Here's my custom call handler constructor:

        public MyCustomHandler(string message)
        {
            Console.WriteLine(message);
        }

And to pass a parameter value from the config, you can do something like this.

	<callHandler name="Handler" type="CustomObjects.MyCustomHandler, UnityInterceptionDrills">
            <constructor>
              <param name="message" value="test" />
            </constructor>
          </callHandler>   

And that should be it, a "test" string should be pass into the message parameter in MyCustomHandler costructor.

Though if you would want to do is to be able to get the value of the parameter that is being pass every call to the method being intercepted, this is actually accessible in the CustomHandler IMethodReturn Invoke method particularly in the IMethodInvocation object pass to the said method in its Arguments collection property. HTH.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 25, 2011 at 3:45 PM

Hi,

Thank you for your help.

It seems it will send the same message to the intercepted method. And I want to post to the different message.

And I have the other question that What should I do if I want to bind the different handler to the method.

Such:

class TestClass

{

[CallHandlerA]

[CallHanderB]

void MethodA();

 

[CallHandlerB]

void MethodB();

 

}

 

What should I do if I want to realize it with the configuration. Thank you very much.

Jun 26, 2011 at 5:32 PM

If I understand your question correctly, what you mean is assigning multiple call handler in a single method right? If yes, then yes this is feasible. All you need to do is to add all call handler that you would want to associate in your method that will be intercepted.

It is just more like having a multiple call handler in a particular policy.

 <interception>
        <policy name="MyPolicy">
          <matchingRule name="MemberNameMatch" type="MemberNameMatchingRule">
            <constructor>
              <param name="nameToMatch" value="SayHello" />
            </constructor>    
          </matchingRule>
          <callHandler name="Handler1" type="CustomObjects.MyCustomHandler, UnityInterceptionDrills">
            <constructor>
              <param name="message" value="test" />
            </constructor>
          </callHandler>
          <callHandler name="Handler2" type="CustomObjects.MyCustomHandler, UnityInterceptionDrills">
            <constructor>
              <param name="message" value="test2" />
            </constructor>
          </callHandler>
        </policy>
      </interception>

Hope this helps.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com