Right, almost there, the problem I have now, is that the hook's ShouldInterceptMethod gets passed the interface's method (I add the interceptor to the model in the contributor), which works ok if the service is a class, but if the service is an interface, and the attribute is on the implementing class method, then the hook thinks it doesn't need to intercept, is there a way to get the attributes on the service implementation from the hook?
The main reason I am doing this is so that we don't check the attributes on every method call and wanted to make use of hook's caching. Am I better off implementing my own attribute caching in the interceptor? . Just found out about the TransacionFacility, will have a look and see if I can steal any ideas. On Sat, Jan 29, 2011 at 2:42 AM, Seif Attar <[email protected]> wrote: > brilliant! thanks! I can go to sleep now :) Will try it out tomorrow! > > 2011/1/29 Krzysztof Koźmic <[email protected]>: >> Actually I think ComponentModel construction contributor would be more >> appropriate here (doco: >> http://stw.castleproject.org/Windsor.ComponentModel-construction-contributors.ashx >> ) >> You can set hook via the following code in the contributor >> >> var proxyOptions = ProxyUtil.ObtainProxyOptions(model, true); >> proxyOptions.Hook = new InstanceReference<IProxyGenerationHook>(yourHook); >> >> HTH, >> Krzysztof >> >> On 29/01/2011 12:11 PM, Seif Attar wrote: >>> >>> Hello, >>> >>> SharpArchitectureContrib currently has a logging facility, that works by: >>> 1. Handling KernelComponentRegistered and adding the LogInterceptor if >>> the class has the LogAttribute decorated on it, its assembly or any of >>> its methods. >>> 2. In the interceptor Intercept implementaion it checks if the current >>> method being intercepted, its class or its assembly has the attribute, >>> and logs accordingly. >>> >>> I don't like the fact that all this reflection happen, and after >>> reading the docs and Krzysztof Koźmic's tutorial I decided to replace >>> this with selector and hook, I think I need to replace 1 with a >>> IModelInterceptorsSelector (I got this part working) and 2 with >>> ProxyGenerationHook, which I can't figure out how to hook up! >>> >>> in the facility, I do >>> >>> this.Kernel.ProxyFactory.AddInterceptorSelector(LoggingInteceptorSelector()); >>> >>> and in the ModelInterceptorsSelector: >>> >>> public bool HasInterceptors(ComponentModel model) >>> {//check the service and implementaion, since the Log >>> attribute might be declared on either >>> return >>> AttributeExtractor<T>.ShouldInterceptType(model.Implementation) || >>> (model.Implementation != model.Service&& >>> AttributeExtractor<T>.ShouldInterceptType(model.Service)); >>> } >>> >>> public InterceptorReference[] SelectInterceptors(ComponentModel model, >>> InterceptorReference[] interceptors) >>> { >>> var selectedInterceptors = new >>> InterceptorReference[interceptors.Length + 1]; >>> interceptors.CopyTo(selectedInterceptors, 0); >>> selectedInterceptors[selectedInterceptors.Length - 1] = >>> new InterceptorReference(typeof(LogInterceptor).Name); >>> return selectedInterceptors; >>> } >>> >>> Where can I add ProxyGenerationHook? or am I going at this the wrong >>> way? suggestions? >>> >>> Thanks, >>> Seif >>> >> >> -- >> 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.
