我正在尝试使用 Autofac 进行某种拦截。目前我已经配置了一些 bll 对象:
updater.RegisterGeneric(typeof(BaseBll<>))
.AsImplementedInterfaces()
.InstancePerRequest()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies)
.InterceptedBy(typeof(ActivityLogger));
updater.Register(c => new ActivityLogger());
我将拦截属性放在其中一个类上:
[Intercept(typeof(ActivityLogger))]
public class MyClassBll : BaseBll<TModel>, IMyClassBll
不幸的是,从 MyClassBll 调用某些方法时不会调用 Intercept 方法。如果您有任何想法,如何解决这个问题,请告诉我。
现在我找到了临时解决方法:
updater.RegisterType<MyClassBll>().As<IMyClassBll>().EnableInterfaceInterceptors();