Autofac.Extras.DynamicProxy icon indicating copy to clipboard operation
Autofac.Extras.DynamicProxy copied to clipboard

Conditional registration for interceptors

Open tillig opened this issue 5 years ago • 0 comments

Problem Statement

Based on autofac/Autofac#1211 - it may be interesting to have the ability to conditionally enable interception based on a lambda expression. This does somewhat overlap with #29.

Desired Solution

I imagine the usage would be like:

builder
  .RegisterAssemblyTypes(typeof(Program).Assembly)
  .AsClosedTypesOf(typeof(ICommandHandler<,>))
  .EnableInterfaceInterceptors(t => t.HasSpecificAttributeICareAbout())
  .InterceptedBy(typeof(LoggingInterceptor));

That is, you could act on the registration based on the type being registered. (Honestly, this part needs some work. I haven't thought it all the way through. It may be there's a better way to go here.)

tillig avatar Oct 08 '20 14:10 tillig