Forcing Castle Windsor to Generate Class Proxies
2010-04-21

I don't know why it took me so long to come up with this idea, but to save others potential headaches...have you ever thought "hmmmm, I registered this as an interface with an implementation, but I want Windsor to use a class proxy, not an interface proxy, how do I do that?"

For me, initially I almost went as far as implementing my own ProxyFactory to force it to use class proxy no matter what, and then the light bulb hit me and it turns out that there's a much easier way to accomplish this.

c.Register(Component.For<ConcreteImpl, IService>().Interceptors<AnInterceptor>());

Tada!  The actual service is now a concrete type, so Windsor will go, OK, I need to create a class proxy.  But since it's forwarded to the interface as well, all your dependencies can simply use the interface and everything magically works.

Yay!

Comments

bling
void IService.SomeLongRunningOperation() {
Action1();
Action2();
Action3();
}

protected virtual void Action1() {}
protected virtual void Action2() {}
protected virtual void Action3() {}

Without class proxies, those action methods could not be intercepted, and in our case, we would not be able to collect metrics/statistics on those methods.
Krzysztof Koźmic (2)
Why did you want a class proxy for interface service?