Конфигурация перехвата Autofac для генериков
Я пытаюсь сделать какой-то перехват с помощью 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
К сожалению, метод Intercept не вызывается при вызове некоторых методов из MyClassBll. Если у вас есть идеи, как это можно исправить, пожалуйста, дайте мне знать.
На данный момент я нашел временное решение:
updater.RegisterType<MyClassBll>().As<IMyClassBll>().EnableInterfaceInterceptors();
1 ответ
Похоже, что в Autofac есть ошибка с внедрением свойства, ее замена на конструктор решает проблему.
You forgot to include.EnableInterfaceInterceptors() or.EnableClassInterceptors() before the.InterceptedBy(). Take a look here: https://autofaccn.readthedocs.io/en/latest/advanced/interceptors.html
[UPDATE]
As requested, I provided a code sample, based on the posted code:
updater.RegisterGeneric(typeof(BaseBll<>))
.AsImplementedInterfaces()
.InstancePerRequest()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies)
.EnableInterfaceInterceptors()
.InterceptedBy(typeof(ActivityLogger));