bonskijr
bonskijr

Reputation: 29

How to an an (method) Interceptor with generic components installation

Given the following code:

    container.Register(
            AllTypes.FromAssemblyNamed("MyNameSpace")
                    .Where(component => component.Name.EndsWith("Repository"))
                    .WithService.FirstInterface()
                    .Configure(component => component.LifeStyle.Singleton)
        );

Is it possible to introduce an Interceptor(eg LoggingInterceptor) for all components found? My only recourse now is to break each components and add the Interceptor explicitly, which I found counter intuitive since they'll be using one interceptor(ie LoggingInterceptor).

Thanks

Upvotes: 1

Views: 517

Answers (1)

roelofb
roelofb

Reputation: 581

container.Register(
                AllTypes.FromAssemblyNamed("MyNameSpace")
                        .Where(component => component.Name.EndsWith("Repository"))
                        .WithService.FirstInterface()
                        .Configure(component => component.LifeStyle.Singleton.Interceptors(InterceptorReference.ForType<LoggingInterceptor>()))
            );
container.Register(Component.For<LoggingInterceptor>());

Upvotes: 1

Related Questions