Created
June 30, 2010 12:17
-
-
Save jfromaniello/458571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyFacility : AbstractFacility | |
{ | |
protected override void Init() | |
{ | |
Kernel.ComponentRegistered += Kernel_ComponentRegistered; | |
} | |
void Kernel_ComponentRegistered(string key, IHandler handler) | |
{ | |
if (typeof(MyControllerBase).IsAssignableFrom(handler.Service)) | |
{ | |
handler.ComponentModel.Interceptors | |
.Add(InterceptorReference.ForType<MyInterceptor>() | |
.SelectWith(new MyInterceptorSelector())); | |
} | |
} | |
} | |
public class MyInterceptorSelector : IInterceptorSelector | |
{ | |
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) | |
{ | |
if(method.GetCustomAttributes(typeof(MyAttribute), true).Any()) | |
{ | |
return interceptors; | |
} | |
return new IInterceptor[]{}; | |
} | |
} | |
public class MyAttribute : Attribute | |
{ | |
} | |
public class MyInterceptor : IInterceptor | |
{ | |
public void Intercept(IInvocation invocation) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment