So, finally i created some tests. With the *shouldfind_method* test i'm not
sure if it is a bug or not.
The problem here is that the proxy has two methods with the same name and
signature. This is logic since
in the tested case one interface is given twice to the ProxyGenerator. I'm
just wondering why this doesn't result
in an exception. With the real case the problem is, it is not startable with
NUnit, Gallio etc. They both crashed.
Hope you can find something...
2009/6/25 Belvasis <[email protected]>
> Yes i'll do it later this evening, i'm on travel right now
>
> Regards
>
> Am 25.06.2009 um 16:45 schrieb Ayende Rahien <[email protected]>:
>
> That most definitely should not.Can you create a test case?
>
> On Thu, Jun 25, 2009 at 5:41 PM, Belvasis < <http://belvasis.de>
> belvasis.de@ <http://googlemail.com>googlemail.com> wrote:
>
>> Now i'm confused ;) Did you think i called the MethodInfo.Invoke from
>> inside the intercepto? No, no i didn't. That this results in an endless loop
>> is clear. I did simply:
>> Obj = CreateInterfacProxyWithTarget
>> pMethod.Invoke(obj...)
>>
>> And Inside the interceptor:
>>
>> ...
>> If( check(...))
>> invocation.proceed()
>>
>> This leads to a StackOverflow...
>>
>> Am 25.06.2009 um 16:09 schrieb Ayende Rahien < <[email protected]>
>> [email protected]>:
>>
>> It _is_, from the OUTSIDE.You are calling this from the intereceptor!
>>
>> On Thu, Jun 25, 2009 at 5:03 PM, Belvasis <
>> <http://belvasis.de><http://belvasis.de>
>> belvasis.de@ <http://googlemail.com> <http://googlemail.com>
>> googlemail.com> wrote:
>>
>>> No thats not what i want or need :( I thought it would be completely
>>> transparent for the user of the object if it i proxied or not. This is true
>>> if you work with the public signature of the object, but not if you use
>>> reflection as far as i can see. I wanted the developer to call something
>>> like TaskRegistry.invokeTask("taskDef"). In the end this builds a stateless
>>> Task object. Every method of the Task can be decorated with an
>>> TaskImplementor("taskDef") Attribute and those methods should be intercepted
>>> to check availability, permission etc., if the are invoked. So i have to use
>>> reflection for it. Maybe i have to think about other ways to do this.
>>>
>>> Regards
>>>
>>>
>>> Am 25.06.2009 um 10:01 schrieb Ayende Rahien <
>>> <[email protected]><[email protected]>
>>> [email protected]>:
>>>
>>> Yes, that is what you want, no?
>>>
>>> On Thu, Jun 25, 2009 at 10:50 AM, Belvasis <
>>> <http://belvasis.de><http://belvasis.de><http://belvasis.de>
>>> belvasis.de@ <http://googlemail.com>
>>> <http://googlemail.com><http://googlemail.com>
>>> googlemail.com> wrote:
>>>
>>>> But if i invoke the method on the DynProxyGetTarget() - object it
>>>> bypasses the interceptor, or do Ido something wrong? On the other hand
>>>> what you say means, you have alwys to know if an object is a proxy or
>>>> not. Is this wanted?
>>>>
>>>> Thanks and regards
>>>>
>>>> Am 25.06.2009 um 02:01 schrieb Ayende Rahien <
>>>> <[email protected]><[email protected]><[email protected]>
>>>> [email protected]>:
>>>>
>>>> That is the expected behavior.Invoking a method using Invoke will mean
>>>> that you get back to the interceptor.
>>>> The workaround you specified is how this should work.
>>>>
>>>> On Thu, Jun 25, 2009 at 2:55 AM, Belvasis <
>>>> <http://belvasis.de><http://belvasis.de><http://belvasis.de><http://belvasis.de>
>>>> belvasis.de@ <http://googlemail.com>
>>>> <http://googlemail.com><http://googlemail.com><http://googlemail.com>
>>>> googlemail.com> wrote:
>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> >
>>>>>
>>>>> > Hi,
>>>>> > I have the following problem:
>>>>> > I want to invoke a method on a proxy
>>>>> > using MethodInfo.Invoke(...). The method should be intercepted, if
>>>>> the
>>>>> > InterceptorSelector decided to do so.
>>>>> > The problem is, that the Interceptor.Intercept method is called in
>>>>> > an endless loop, if invocation.Proceed is called Inside the
>>>>> > interceptor. Anyone an idea why this happend? If i invoke the
>>>>> > corresponding MethodInfo of the DynProxyGetTarget() - object, it
>>>>> > works as expected.
>>>>> >
>>>>> > Thanks
>>>>> > Belvasis
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Castle.DynamicProxy;
using Castle.Core.Interceptor;
namespace tests
{
[TestFixture]
public class CreateProxy_Test
{
[Test]
public void shouldfind_ITask_method_using_CreateInterfaceProxyWithTarget()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTarget<ITask>(pResult, new
ProxyGenerationOptions(), new TaskInterceptor());
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStart");
Assert.IsNotNull(pMethod);
}
[Test]
public void
should_not_find_ITaskToo_method_using_CreateInterfaceProxyWithTarget()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTarget<ITask>(pResult, new
ProxyGenerationOptions(), new TaskInterceptor());
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStartExt");
Assert.IsNull(pMethod);
}
[Test]
public void
shouldfind_ITask_method_using_CreateInterfaceProxyWithTargetInterface()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTargetInterface(typeof(ITask),
pResult.GetType().GetInterfaces(), pResult, new ProxyGenerationOptions(), new
TaskInterceptor());
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStart");
Assert.IsNotNull(pMethod);
}
[Test]
public void
shouldfind_ITaskToo_method_using_CreateInterfaceProxyWithTargetInterface()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTargetInterface(typeof(ITask),
pResult.GetType().GetInterfaces(), pResult, new ProxyGenerationOptions(), new
TaskInterceptor());
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStartExt");
Assert.IsNotNull(pMethod);
}
[Test]
public void
invoke_ITask_method_using_CreateInterfaceProxyWithTarget_shouldnotthrow()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTarget<ITask>(pResult, new
ProxyGenerationOptions(), new TaskInterceptor());
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStart");
Assert.IsNotNull(pMethod);
Assert.DoesNotThrow(delegate
{
pMethod.Invoke(pProxyResult, new object[] { });
});
}
[Test]
public void
invoke_ITask_method_using_CreateInterfaceProxyWithTargetInterface_shouldnotthrow()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTargetInterface(typeof(ITask),
pResult.GetType().GetInterfaces(), pResult, new ProxyGenerationOptions(), new
TaskInterceptor()) as ITask;
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStart");
Assert.IsNotNull(pMethod);
Assert.DoesNotThrow(delegate
{
pMethod.Invoke(pProxyResult, new object[] { });
});
}
[Test]
public void
invoke_ITaskToo_method_using_CreateInterfaceProxyWithTargetInterface_shouldnotthrow()
{
var pResult = new Task();
//Create proxy
var pProxyResult = new
ProxyGenerator().CreateInterfaceProxyWithTargetInterface(typeof(ITask),
pResult.GetType().GetInterfaces(), pResult, new ProxyGenerationOptions(), new
TaskInterceptor()) as ITask;
//Find method
MethodInfo pMethod = pProxyResult.GetType().GetMethod("doStartExt");
Assert.IsNotNull(pMethod);
Assert.DoesNotThrow(delegate
{
pMethod.Invoke(pProxyResult, new object[] { });
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Castle.DynamicProxy;
using Castle.Core.Interceptor;
namespace tests
{
public interface ITaskToo
{
void doStartExt();
}
public interface ITask
{
void doStart();
}
public class Task : ITask, ITaskToo
{
//From ITask
virtual public void doStart() { }
//From ITaskToo
virtual public void doStartExt() {}
}
public class TaskInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (true)
{
invocation.Proceed();
}
}
}
}