0

I'm trying to create a facility that will add some interceptor to the registered class based on the class attribute. This is my facility:

public class MyFacility : AbstractFacility
{
     protected override void Init()
    {
        this.Kernel.ComponentRegistered += (s, h) =>
        {
            if (h.ComponentModel.Implementation.GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
            {
                h.ComponentModel.Interceptors.Add(InterceptorReference.ForType<MyInterceptor>());
            }
        }
    }
}

but this way, when I use the this keyword in a class method it refers to the target class not the proxy class and this makes some framework that I use don't work properly.

I need to create with a facility the same proxy that is generated with the ProxyGenerator.CreateClassProxy<MyClass>() method.

How can I achieve this?

Marijn
  • 10,367
  • 5
  • 59
  • 80
Gigitsu
  • 593
  • 6
  • 19
  • Could you show more code? Is the component you are registering an interface or a class? – svick Jul 17 '11 at 12:30
  • the componenti I'm registering is an interface. Thi is the windsor installation: _wc = new WindsorContainer(); _wc.AddFacility(); _wc.Register( Component.For() ); _wc.Register( Component.For(). ImplementedBy() ); – Gigitsu Jul 17 '11 at 12:47

1 Answers1

1

Expose the class as a service on your component.

container.Register(
   Component.For<SomeClass,ISomeInterface>().Lifestyle.Whatever.Interceptors<SomeInterceptor>()
);
Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115