0

Autofac を使用して、ある種の傍受を試みています。現在、いくつかの bll オブジェクトを構成しています。

updater.RegisterGeneric(typeof(BaseBll<>))
            .AsImplementedInterfaces()
            .InstancePerRequest()
            .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies)
            .InterceptedBy(typeof(ActivityLogger));
updater.Register(c => new ActivityLogger());

クラスの 1 つに Interception 属性を設定します。

[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 に答える