I think it's because the proxy is an interface proxy, try getting the
method invocation target:

            MethodInfo methodInfo = invocation.MethodInvocationTarget;
            if (methodInfo == null) {
                methodInfo = invocation.Method;
            }

and get the attributes from methodInfo



On 8 June 2011 11:24, Paul <[email protected]> wrote:
>
> I'm currently implementing Interceptors using Castle DynamicProxy. I
> require the interceptor to pick up some custom attributes on my
> service layer method, but invocation.Method.GetCustomAttributes
> returns nothing. Anything I could be doing wrong?
>
> Intercepted Method:
>
>     [SecurityRole(AuthenticationRequired = false, Role =
> SystemRole.Unauthorised)]
>     public virtual void LoginUser(out SystemUser userToLogin, string
> username)
>     {
>         ...
>     }
>
>
> Interceptor:
>
>    // Checks that a security attribute has been defined
>    foreach (SecurityRoleAttribute role in
> invocation.Method.GetCustomAttributes(typeof(SecurityRoleAttribute),
> true))
>    {
>        if (!securityAttributeDefined)
>            securityAttributeDefined = true;
>    }
>
> I've also tried:
>
>    Attribute.GetCustomAttribute(invocation.Method,
> typeof(SecurityRoleAttribute), true);
>
> May be a configuration issue. The config code is as follows:
>
> InterceptorsInstaller:
>
>        public void Install(IWindsorContainer container,
> IConfigurationStore store)
>        {
>             container.Register(
>
> Component.For<LoggingInterceptor>().LifeStyle.Transient
>                );
>
>             container.Register(
>
> Component.For<SecurityInterceptor>().LifeStyle.Transient
>                );
>
>             container.Register(
>
> Component.For<ValidationInterceptor>().LifeStyle.Transient
>                );
>        }
>
> ServiceInstaller:
>
>        public void Install(IWindsorContainer container,
> IConfigurationStore store)
>        {
>            InterceptorReference[] interceptors = {new
> InterceptorReference(typeof(SecurityInterceptor)), new
> InterceptorReference(typeof(LoggingInterceptor)), new
> InterceptorReference(typeof(ValidationInterceptor)) };
>
>
> container.Register(AllTypes.FromAssemblyContaining<BaseService>().Pick()
>                                
> .If(Component.IsInSameNamespaceAs<LoginService>())
>                                .If(t => t.Name.EndsWith("Service"))
>                                .Configure(c => c
>                                                   .LifeStyle.Transient
>                                                   
> .Interceptors(interceptors).Anywhere)
>                                .WithService.AllInterfaces());
>        }
>
> I'm Using Castle 2.5.1 (from NuGet)/.Net 3.5.
>
> Thanks,
>
> Paul
>
> --
> 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.
>

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

Reply via email to