No you cant - adding interceptor is a fine grained task and you seldom
want to apply them globally.
If you do though - nothis is stopping you from adding a helper method in
your installer and registering through it.
HTH
Krzysztof
On 9/08/2010 11:36 PM, PB wrote:
Finally got it working, have couple of questions though.
This is what I did:
public class LoggingProxyGenerationHook : IProxyGenerationHook
{
public bool ShouldInterceptMethod(Type type, MethodInfo
methodInfo)
{
return GetLogAttribute(methodInfo) != null;
}
private static LogAttribute
GetLogAttribute(ICustomAttributeProvider methodInfo)
{
object[] logAttribute = methodInfo.GetCustomAttributes(typeof
(LogAttribute), true);
if (logAttribute.Length == 0)
{
return null;
}
else
{
return (LogAttribute) logAttribute[0];
}
}
}
container.Register(Component.For<LogInterceptor>(),
Component.For<LoggingProxyGenerationHook>(),
Component.For<ILogger>().ImplementedBy<Logger>(),
Component.For<IFoo>().ImplementedBy<Foo>().Interceptors<LogInterceptor>().Proxy.Hook(
h =>
h.Service<LoggingProxyGenerationHook>()));
The above code registers LogInterceptor for implementation of IFoo.
What if I want to use the interceptor with every interface
implementation that is instantiated through the container. Is there a
global level where we can register the interceptor and the proxy hook,
in order to avoid the repetitive task of registeration for each
interface.
Thanks
On Jul 23, 1:25 pm, Krzysztof Koźmic<[email protected]>
wrote:
Looks like it's missing from v2.1
You'd have to write custom descriptor and call AddDescriptor(new
MyDescriptor(new SomeHook()));
In the descriptor you override the ApplyToModel method like this:
ProxyUtil.ObtainProxyOptions(model, true).Hook= this.hook;
or you can upgrade to v2.5 which has that.
HTH,
Krzysztof
On 23/07/2010 1:08 PM,PBwrote:
do you know what that way would be?
On Jul 20, 12:54 pm, Krzysztof Koźmic<[email protected]>
wrote:
Correct, that was added recently. I think there was some way of
specifying hook in v2.1.1 though
On 20/07/2010 12:52 PM,PBwrote:
Hi
Thanks for reply. I am using v2.1.1 and there is no implementation of
Hook
Proxy.Hook(h => h.Service<ProxyNothingHook>()
Regards
On Jul 13, 9:58 pm, Krzysztof Koźmic<[email protected]>
wrote:
You don't register PGO, but you can configure all relevant aspects of
the proxy mechanism.
In trunk version of Windsor you can do:
var interceptor = new ResultModifierInterceptor(5);
container.Register(Component.For<ResultModifierInterceptor>().Instance(interceptor),
Component.For<ProxyNothingHook>(),
Component.For<ICalcService>()
.ImplementedBy<CalculatorService>()
.Interceptors<ResultModifierInterceptor>()
.Proxy.Hook(h =>
h.Service<ProxyNothingHook>()));
var calc = container.Resolve<ICalcService>();
Assert.AreEqual(4,calc.Sum(2,2));
In version v2.1.1 something similar although you can provide hook only
as an instance IIRC.
Version 2.5 beta1 does not have it which is my omission. Beta2 and final
version will work like the sample above
Krzysztof
On 13/07/2010 9:53 PM,PBwrote:
I came across this article of your on Selecting which methods to
intercept which shows an implementation of ProxyGenerationOptions with
ProxyGenerationHook. I am using windsor container and register types
as follow
IWindsorContainer container = new WindsorContainer();
container.Register(
Component.For<IFoo>().ImplementedBy<Foo>(),
Component.For<ILogger>().ImplementedBy<Logger>(),
Component.For<LogInterceptor>().LifeStyle.Transient);
could you please indicate how can i register ProxyGenerationOptions
using windsor container. Thanks
http://kozmic.pl/archive/2009/01/17/castle-dynamic-proxy-tutorial-par...
On Jul 10, 11:15 pm, Krzysztof Koźmic<[email protected]>
wrote:
using either IProxyGenerationHook, or IIntreceptorSelector
Component.For<IFoo>().ImplementedBy<Foo>().Interceptors<SomeInterceptor,
SomeOtherInterceptor>()
2010/7/10PB<[email protected]>:
thanks. then how can i prevent a method from being intercepted for
interfaces?
regards.
On Jul 9, 8:05 pm, Krzysztof Koźmic<[email protected]>
wrote:
You're mixing stuff up here. Attributes and being virtual are unrelated.
Class components need to have methods virtual to be interceptable.
Interfaces are virtual by definition.
You don't need attributes at all - just assign interceptor to the
component when registering it.
Krzysztof
On 9/07/2010 12:30 PM,PBwrote:
I use Windsor container for DI in my application. I want to implement
interception and confused wether I'll have to change the existing
implementation to use Dynamic Proxy to create objects so that they can
be intercepted or is there a way to integrate with existing Windsor
container.
Also how can I implement attribute based method interception? I don't
want classes to be attributed with
[Interceptor(typeof(LogInterceptor))] and then create virtual methods.
Ninject allows you to derive your attribute class from
InterceptAttribute class and decorate methods for interception.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Method,
AllowMultiple = false, Inherited = true)]
public class LogAttribute : InterceptAttribute
{
public override IInterceptor CreateInterceptor(IProxyRequest
request)
{
return request.Context.Kernel.Get<LogInterceptor>();
}
}
Is it achievable with castle?
Thanks- Hide quoted text -
- Show quoted text -
--
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
athttp://groups.google.com/group/castle-project-users?hl=en.-Hidequotedtext -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
--
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.