拦接器
public class AutoDesensitizationMethodInterceptor : IMethodInterceptor { public object Intercept(IMethodInvocation invocation, params object[] args) { MethodInfo methodInvocationTarget = invocation.MethodInvocationTarget; object obj = invocation.Proceed(args); return AttributeVerification.VerificationDesensitization<Object>(obj); } }
拦接器
public class AutoDesensitizationInspector : IContributeComponentModelConstruction { /// <summary> /// /// </summary> /// <param name="kernel"></param> /// <param name="model"></param> // Token: 0x0600048E RID: 1166 RVA: 0x00010344 File Offset: 0x0000E544 public void ProcessModel(IKernel kernel, ComponentModel model) { //ICacheFactory autoCacheManager = kernel[typeof(IAutoCacheManager)] as IAutoCacheManager; foreach (MethodInfo m in model.Implementation.GetMethods()){ if (m.IsDefined(typeof(DesensitizationMethodAttribute), true)) { model.Interceptors.Add(new InterceptorReference(typeof(AutoDesensitizationMethodInterceptor))); } } }
public class AutoDesensitizationFacility : AbstractFacility { protected override void Init() { base.Kernel.ComponentModelBuilder.AddContributor(new AutoDesensitizationInspector()); base.Kernel.AddComponent("AutoDesensitization", typeof(AutoDesensitizationMethodInterceptor)); } }
配置web.config
<castle> <facilities> <facility id="AutoDesensitization" type="命名空间.AutoDesensitizationFacility, 程序集" /> </facilities> </castle>