0

我正在尝试使用 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();
4

2 回答 2

0

Autofac似乎有一个属性注入的错误,将其更改为构造函数注入解决了这个问题。

于 2014-09-05T06:25:04.810 回答
0

您忘记在 .InterceptedBy() 之前包含 .EnableInterfaceInterceptors() 或 .EnableClassInterceptors()。看看这里:https ://autofaccn.readthedocs.io/en/latest/advanced/interceptors.html

[更新]

根据要求,我根据发布的代码提供了一个代码示例:

updater.RegisterGeneric(typeof(BaseBll<>))
  .AsImplementedInterfaces()
  .InstancePerRequest()
  .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies)
  .EnableInterfaceInterceptors()
  .InterceptedBy(typeof(ActivityLogger));
于 2019-07-31T12:55:17.517 回答