Story started this way, I used Castle EventWiring facility to define listeners to events in my classes, and it worked fine, I used to raise events like this:
if (null != BlaBlaEvent)
{
BlaBlaEvent(someData);
}
Recently I faced a business requirement and thought probably the best solution is to use a proxy pattern so I used DynamicProxy, in my IoC resolving function (a small wrapper to Castle Windsor) I have the following code:
T componenet = _container.Resolve<T>();
var gen = new ProxyGenerator();
if (typeof(T).IsClass)
{
return gen.CreateClassProxyWithTarget(componenet, _container.Resolve<StashInterceptor>());
}
else
{
return gen.CreateInterfaceProxyWithTarget(componenet, _container.Resolve<StashInterceptor>());
}
this also worked, and instead of returning a concrete class it returns a proxy that intercepts the function calls and does some processing, then forwards the call to the original concrete class methods.
problem now is that the events in the concrete class have no listeners (Even though the configurations says they do).
not sure if this is a bug or a design decision not to load the listeners when invoking the method from a proxy, but currently I'm in a boggle and need a solution or a workaround.
Anyone has an idea?
Here are my castle xml configurations in web.config:
<castle>
<facilities>
<facility id="event.wiring" type="Castle.Facilities.EventWiring.EventWiringFacility, Castle.Facilities.EventWiring" />
</facilities>
<components>
<component id="SomeInterceptor" type="Namespace.SomeInterceptor, MyAssembly" />
<component id="SomePublisher" type="Namespace.SomePublisher, MyAssembly">
<subscribers>
<subscriber id="SomeSubscriber" event="SomeEvent" handler="OnSomeEvent" />
</subscribers>
</component>
<component id="SomeSubscriber" type="Namespace.SomeSubscriber, MyAssembly" />
</components>