Interceptors interfaces in Windsor 3.0

228 views
Skip to first unread message

Johannes Gustafsson

unread,
Feb 8, 2012, 3:15:21 PM2/8/12
to castle-pro...@googlegroups.com
Hi all,

In Windsor version 2.5.2 this code works:

  [Interceptor(typeof(IInterceptorForFoo))]
  public class Foo
  {
public string Value { get; set; }
  }

  public interface IInterceptorForFoo : IInterceptor
  {
  }

  public class InterceptorForFoo : IInterceptorForFoo
  {
public void Intercept(IInvocation invocation)
{
}
  }


  var container = new WindsorContainer();

  container.Register(
    Component.For<Foo>(),
    Component.For<IInterceptorForFoo>().ImplementedBy<InterceptorForFoo>()
  );

  container.Resolve<Foo>();

In 3.0 however, I get the following exception when trying to resolve IFoo: 

Castle.MicroKernel.ComponentActivator.ComponentActivatorException : ComponentActivator: could not proxy Foo
----> Castle.MicroKernel.Resolvers.DependencyResolverException : The interceptor 'IInterceptorForFoo' could not be resolved. Component 'InterceptorForFoo' matching the type specified was found in the container. Did you mean to use it? If so, please specify the reference via name, or register the interceptor without specifying its name.

How do I register an interceptor without specifying its name?

Regards,
Johannes

Krzysztof Koźmic

unread,
Feb 8, 2012, 4:13:10 PM2/8/12
to castle-pro...@googlegroups.com
  [Interceptor(typeof(InterceptorForFoo))]
  public class Foo
  {
public string Value { get; set; }
  }

or

  [Interceptor("fooFoo")]
  public class Foo
  {
public string Value { get; set; }
  }

and specify .Named("fooFoo") when registering the interceptor
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Clark

unread,
Apr 12, 2012, 9:43:09 AM4/12/12
to castle-pro...@googlegroups.com
Kryzsztof, Johannes,

First, thanks, Kryssztof, for the .Named() fix - that worked.  But that sent us looking a little bit more closely, and now it seems more like a bug, or at least a behavior change from 3.0 beta1.  We used almost the exact same construct that worked fine until we switched to the 3.0 release binaries.  Then we had to switch our interceptor registration/usage from this:

      handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(IFooInterceptor)));

to this:

      handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(FooInterceptor)));

where the interface was registered a la:

windsorContainer.Register(
      Component.For<IFooInterceptor>().ImplementedBy<FooInterceptor>().DependsOn(
      Dependency.OnValue("someValue", _someValue)).LifeStyle.Singleton);


Registering the interceptor with the interface instead of the base type worked in 3.0 Beta1 or thereabouts.  At that point we were building our own binaries, but with no source changes other than also building mono versions with some #defines set.

Thanks for any pointers as to why this is different - I realize there may be some points about interceptors that I don't get yet that might make this obvious as to why it behaves this way now.

-- 
Clark
Reply all
Reply to author
Forward
0 new messages