It sounds like you mean a regular dynamic interceptor, which by default works on the Ninject Interception extension.
Here is an example of conditional interception:
class CustomInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (invocation.Request.Method.Name == "MethodToIntercept")
Console.WriteLine("Intercepted!");
invocation.Proceed();
}
}
You bind it directly to one class, for example:
public class MyModule : NinjectModule
{
public override void Load()
{
Bind<IFoo>().To<MyFoo>().Intercept().With<CustomInterceptor>();
}
}
And that’s almost all you need to do if you want to dynamically intercept one class.
Kernel extensions look promising because they allow you to write conditions directly in the declaration:
kernel.Intercept(ctx => ctx.Request.Service == typeof(IFoo))
.With<CustomInterceptor>();
, , , . , , ( ) .
run-or-don't-run , .
, (/) , , . , Ninject Interception , -. Castle , - - , . Ninject-DP2, Ninject.
Ninject Interception , , Castle DP2 . , , , .