0

I'm trying to do some sort of interception by using Autofac. Currently I've some bll objects configured:

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

I put Interception attribute on one of the classes:

[Intercept(typeof(ActivityLogger))]
public class MyClassBll : BaseBll<TModel>, IMyClassBll

Unfortunately, the Intercept method is not called when calling some methods from MyClassBll. If you have any ideas, how this might be fixed, please let me know.

For now I've found temp workaround:

updater.RegisterType<MyClassBll>().As<IMyClassBll>().EnableInterfaceInterceptors();
Daemon025
  • 87
  • 1
  • 11

2 Answers2

0

It seems Autofac has a bug with property injection, changing it to constructor injection solved the problem.

Daemon025
  • 87
  • 1
  • 11
0

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));
bauermann
  • 1
  • 2